Skip to main content

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. 1

    Store a function in a variable

    easy10 min

    Store a doubling function in a variable and show the result for 16.

  2. 2

    An anonymous function

    easy10 min

    Store an anonymous function that returns the word Ready.

  3. 3

    Pass a function to map

    easy10 min

    Pass a function expression to map to triple each number, then join with commas.

  4. 4

    A function on an object

    easy10 min

    Give an object an add method and show 2 plus 5.

  5. 5

    A named function expression

    medium10 min

    Use a named function expression to work out factorial of 5.

Find the bug(5)

  1. 1

    Fix the missing assignment

    easy8 min

    The function is never stored, so the variable holds nothing.

  2. 2

    Fix the call before the definition

    easy8 min

    A function expression cannot be used above the line that creates it.

  3. 3

    Fix the wrong function passed

    easy8 min

    The doubling function was passed to map instead of the tripling one.

  4. 4

    Fix the wrong method name

    easy8 min

    The object has no method by that name.

  5. 5

    Fix the missing base case

    easy8 min

    Without 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