JavaScript return Statement — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript return Statement lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Return a value
easy10 minReturn the sum of 3 and 4 from a function.
- 2
Return early
easy10 minReturn a warning when dividing by zero, otherwise divide. Show the zero case.
- 3
No return means undefined
easy10 minShow the word undefined for a function that returns nothing.
- 4
Return an object property
easy10 minReturn an object from a function and show its name property.
- 5
Return from inside a loop
medium10 minReturn the first even number in the list.
Find the bug(5)
- 1
Fix the unreachable code
easy8 minThe real answer sits after a return, so it never runs.
- 2
Fix the missing guard
easy8 minDividing by zero should be caught before the calculation.
- 3
Fix the value on the next line
easy8 minA line break after return makes the function give undefined.
- 4
Fix the return that never happens
easy8 minThe loop finishes without returning the match.
- 5
Fix the return outside the check
easy8 minReturning on every turn means only the first item is ever seen.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace