Skip to main content

JavaScript Function Declarations — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Function Declarations 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

    Declare a function

    easy10 min

    Declare a function named square and show square of 9.

  2. 2

    Call before the declaration

    easy10 min

    Call a declared function on a line above it and show the answer for 7.

  3. 3

    Two parameters

    easy10 min

    Declare a function that joins a first and last name with a space.

  4. 4

    No parameters

    easy10 min

    Declare a function that takes nothing and returns the word Ready.

  5. 5

    Branch inside a function

    medium10 min

    Declare a function returning Adult for 18 or over, Minor otherwise. Show the answer for 15.

Find the bug(5)

  1. 1

    Fix the misspelled keyword

    easy8 min

    The keyword is function, spelled in full.

  2. 2

    Fix the duplicate declaration

    easy8 min

    The later declaration replaces the first one.

  3. 3

    Fix the swapped parameters

    easy8 min

    The names come back in the wrong order.

  4. 4

    Fix the missing space

    easy8 min

    The two names run together with no gap.

  5. 5

    Fix the inverted condition

    easy8 min

    The age test is the wrong way round.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace