All challenges
ProgrammingDebugBeginner4 min
Fix the syntax error
Skills: Debugging · Functions
Task
rectangleArea(width, height) should return the area of a rectangle, but JavaScript refuses to run the program at all. Run it, read the error, then fix the code without changing what the function calculates.What goes wrong
Nothing runs, not even the
console.log at the end: JavaScript reports a SyntaxError before the first line executes.Examples
Run examples tries these. Check solution also runs 2 more tests.
- A 3 by 4 rectangleExample
- Call
- rectangleArea(3, 4)
- Expected
- Returns 12
- A 5 by 5 squareExample
- Call
- rectangleArea(5, 5)
- Expected
- Returns 25
Every test, including the extra ones, is part of this page. Nothing is hidden or secret.
Your code
Loading the editor…
function rectangleArea(width, height) {
const area = width * height;
return area;
console.log(rectangleArea(3, 4));
Ctrl + Enter (⌘ + Enter on a Mac) runs the examples; add Shift to check. Tab indents; press Esc, then Tab, to leave the editor.
Run examples tries your code on the examples and records nothing. Check solution runs every test and saves an attempt.
Tests
Run your code to see which tests pass.
Console
What your code logs with console.log appears here.