code
Generate a responsive navbar in HTML & CSS
html
<!-- Navbar -->
<nav class="navbar">
<div class="logo">MyBrand</div>
<ul class="nav-links" id="navLinks">
<li><a href="#">Home</a></li>
<li><a href="#">Features</a></li>
<li><a href="#">Pricing</a></li>
<li><a href="#">Contact</a></li>
</ul>
<button class="burger" id="burger" aria-label="Toggle menu" aria-expanded="false" aria-controls="navLinks">
<span></span><span></span><span></span>
</button>
</nav>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
.navbar { display: flex; justify-content: space-between; align-items: center;
padding: 1rem 2rem; background: #1a1a2e; color: #fff; position: relative; }
.logo { font-size: 1.5rem; font-weight: 700; color: #e94560; }
.nav-links { display: flex; list-style: none; gap: 2rem; }
.nav-links a { color: #fff; text-decoration: none; font-size: 0.95rem; transition: color 0.3s ease; }
.nav-links a:hover { color: #e94560; }
.burger { display: none; flex-direction: column; gap: 5px; background: none; border: 0; cursor: pointer; }
.burger span { width: 25px; height: 2px; background: #fff; transition: transform 0.3s ease, opacity 0.3s ease; }
.burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger.open span:nth-child(2) { opacity: 0; }
.burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
@media (max-width: 768px) {
.burger { display: flex; }
.nav-links { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column;
gap: 0; background: #1a1a2e; max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.nav-links.open { max-height: 300px; }
.nav-links li { padding: 1rem 2rem; border-top: 1px solid rgba(255,255,255,0.08); }
}
</style>
<script>
const burger = document.getElementById('burger');
const navLinks = document.getElementById('navLinks');
burger.addEventListener('click', () => {
const isOpen = navLinks.classList.toggle('open');
burger.classList.toggle('open', isOpen);
burger.setAttribute('aria-expanded', String(isOpen));
});
</script>

code
Write a Python function to scrape a webpage
python
import requests
from bs4 import BeautifulSoup
def scrape_page(url: str) -> dict:
"""Scrapes a webpage and returns title and all paragraph texts."""
headers = {"User-Agent": "Mozilla/5.0"}
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
except requests.RequestException as e:
return {"error": str(e)}
soup = BeautifulSoup(response.text, "html.parser")
title = soup.find("title")
paragraphs = [p.get_text(strip=True) for p in soup.find_all("p") if p.get_text(strip=True)]
return {
"title": title.get_text(strip=True) if title else "No title found",
"paragraphs": paragraphs[:10]
}
if __name__ == "__main__":
result = scrape_page("https://example.com")
if "error" in result:
print("Failed to scrape:", result["error"])
else:
print(result["title"])
for p in result["paragraphs"]:
print("-", p)

code
Write a SQL query to find top 5 customers by revenue
sql
SELECT
c.customer_id,
c.first_name,
c.last_name,
c.email,
SUM(o.total_amount) AS total_revenue
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE o.status = 'completed'
GROUP BY c.customer_id, c.first_name, c.last_name, c.email
ORDER BY total_revenue DESC
LIMIT 5;

code
Create a React component for a pricing card
jsx
const PricingCard = ({ plan, price, features, isPopular }) => {
return (
<div style={{
border: isPopular ? "2px solid #6c63ff" : "1px solid #e0e0e0",
borderRadius: "16px", padding: "2rem", maxWidth: "300px",
textAlign: "center", position: "relative",
boxShadow: isPopular ? "0 8px 30px rgba(108,99,255,0.2)" : "none"
}}>
{isPopular && (
<span style={{ position: "absolute", top: "-14px", left: "50%",
transform: "translateX(-50%)", background: "#6c63ff", color: "white",
padding: "4px 16px", borderRadius: "20px", fontSize: "0.75rem" }}>
Most Popular
</span>
)}
<h2>{plan}</h2>
<p style={{ fontSize: "2.5rem", fontWeight: "700", color: "#6c63ff" }}>
${price}<span style={{ fontSize: "1rem", color: "#999" }}>/mo</span>
</p>
<ul style={{ listStyle: "none", padding: 0, textAlign: "left" }}>
{features.map((f, i) => (<li key={i}>✓ {f}</li>))}
</ul>
<button style={{ background: isPopular ? "#6c63ff" : "transparent",
color: isPopular ? "white" : "#6c63ff", border: "2px solid #6c63ff",
padding: "0.75rem 2rem", borderRadius: "8px", width: "100%" }}>
Get Started
</button>
</div>
);
};

code
Write a JavaScript function to validate an email and password
javascript
function validateForm(email, password) {
const errors = {};
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!email) {
errors.email = "Email is required.";
} else if (!emailRegex.test(email)) {
errors.email = "Please enter a valid email address.";
}
if (!password) {
errors.password = "Password is required.";
} else if (password.length < 8) {
errors.password = "Password must be at least 8 characters.";
} else if (!/[A-Z]/.test(password)) {
errors.password = "Password must contain at least one uppercase letter.";
} else if (!/[0-9]/.test(password)) {
errors.password = "Password must contain at least one number.";
}
return { isValid: Object.keys(errors).length === 0, errors };
}
