Skip to main content

JavaScript Functions — exercises and bug fixes

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

    Write your first function

    easy10 min

    Write a function that returns the word Hello, then show it.

  2. 2

    Call a function twice

    easy10 min

    Call a counter function twice and show the result.

  3. 3

    Pass a value in

    easy10 min

    Write a function that doubles a number. Show the result for 21.

  4. 4

    Return a calculation

    easy10 min

    Write a function that multiplies price by quantity. Show 25 x 4.

  5. 5

    Reuse one function

    medium10 min

    Use one area function for a square of side 3 and one of side 7, and add the answers.

Find the bug(5)

  1. 1

    Fix the function that is never called

    easy8 min

    The function is defined but nothing runs it.

  2. 2

    Fix the missing brackets

    easy8 min

    Without brackets the function itself is shown, not its result.

  3. 3

    Fix the missing return

    easy8 min

    The function calculates but never sends the answer back.

  4. 4

    Fix the wrong operator

    easy8 min

    The function adds when it should multiply.

  5. 5

    Fix the hard-coded value

    easy8 min

    The function ignores its parameter and always uses 2.

Ready to write the code?

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

Open the workspace