Master JavaScript through hands-on coding challenges. Write real code, get instant feedback, and build practical web development skills.
Write actual JavaScript code to solve each challenge. Your code is validated for correctness.
let - Store a person's full name (e.g., "Sarah Connor"). In JavaScript, strings can be created using single quotes 'text', double quotes "text", or template literals `text`. Use let for variables that may be reassigned later.const - Store the person's age as a number (e.g., 28). JavaScript has only one number type that handles both integers and decimals. Use const for values that won't change - this prevents accidental reassignment and makes your intent clear.let - Store height in meters with decimal precision (e.g., 1.72). Unlike some languages, JavaScript doesn't distinguish between integers and floats - both are simply "number" type. You can verify with typeof height.const - Store true or false to indicate student status. Note: JavaScript booleans are lowercase (true/false), unlike some languages. Booleans are essential for conditional logic and control flow.console.log() to display each variable with a descriptive label. You can use template literals for clean output: console.log(`Name: ${name}`). Alternatively, use string concatenation with the + operator.let - Use for variables that will be reassignedconst - Use for variables that won't change (preferred when possible)var - Older syntax, avoid in modern JavaScript (function-scoped, can cause bugs)`Hello ${name}`typeof variable to check a variable's typevar - it has confusing scoping behaviortrue/false (it's not True/False)Name: Sarah Connor
Age: 28
Height: 1.72
Is Student: true
let name = "Sarah Connor";const age = 28;let height = 1.72;const isStudent = true;console.log(`Age: ${age}`);console.log("Age: " + age);Review feedback below
const variable "score" - Initialize with a test value between 0-100. Try different values (95, 82, 71, 65, 45) to test all grade paths. Use const since the score won't change during execution.let variable "grade" - This will store the letter grade ('A', 'B', 'C', 'D', or 'F'). Use let because we'll assign a value inside the if-else blocks.if (score >= 90) → Grade A (Excellent - top performers)else if (score >= 80) → Grade B (Good - above average)else if (score >= 70) → Grade C (Average - meets expectations)else if (score >= 60) → Grade D (Below Average - needs improvement)else → Grade F (Failing - below 60)>= (greater than or equal), > (greater than), === (strict equality), !== (strict inequality)const status = score >= 60 ? "PASSED" : "FAILED";=== instead of == for comparison (strict equality avoids type coercion bugs)condition ? valueIfTrue : valueIfFalse{} are optional for single-line if statements, but recommended for clarity= (assignment) instead of === (comparison) in conditionselse if and using just if (would check all conditions)Score: 85
Grade: B
Status: PASSED
const score = 85;let grade;if (score >= 90) { grade = "A"; }else if (score >= 80) { grade = "B"; }const status = score >= 60 ? "PASSED" : "FAILED";=== for strict equality comparisonReview feedback below
for (let i = 1; i <= 20; i++) { ... }let i = 1 - initialization (start at 1, use let for block scoping)i <= 20 - condition (continue while i is 20 or less)i++ - increment (add 1 to i after each iteration)i % 3 === 0, then i divides evenly by 3 (no remainder), meaning i IS divisible by 3.9 % 3 = 0 (divisible), 10 % 3 = 1 (not divisible), 15 % 5 = 0 (divisible)let in for loops: for (let i = 1; ...) - this keeps i scoped to the loop&& - both conditions must be true|| - at least one condition must be truei % 15 === 0 (since 15 = 3 × 5)var instead of let in the loop=== (using = instead, which assigns rather than compares)<= not <1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
for (let i = 1; i <= 20; i++) { }if (i % 3 === 0 && i % 5 === 0)if (i % 15 === 0) (since 15 = 3 × 5)15 % 3 === 0 is true (15 ÷ 3 = 5, no remainder)console.log(i);console.log("Fizz");Review feedback below