JavaScript Function Expressions — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Function Expressions 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
Store a function in a variable
easy10 minStore a doubling function in a variable and show the result for 16.
- 2
An anonymous function
easy10 minStore an anonymous function that returns the word Ready.
- 3
Pass a function to map
easy10 minPass a function expression to map to triple each number, then join with commas.
- 4
A function on an object
easy10 minGive an object an add method and show 2 plus 5.
- 5
A named function expression
medium10 minUse a named function expression to work out factorial of 5.
Find the bug(5)
- 1
Fix the missing assignment
easy8 minThe function is never stored, so the variable holds nothing.
- 2
Fix the call before the definition
easy8 minA function expression cannot be used above the line that creates it.
- 3
Fix the wrong function passed
easy8 minThe doubling function was passed to map instead of the tripling one.
- 4
Fix the wrong method name
easy8 minThe object has no method by that name.
- 5
Fix the missing base case
easy8 minWithout a stopping point the recursion never ends.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace