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
Write your first function
easy10 minWrite a function that returns the word Hello, then show it.
- 2
Call a function twice
easy10 minCall a counter function twice and show the result.
- 3
Pass a value in
easy10 minWrite a function that doubles a number. Show the result for 21.
- 4
Return a calculation
easy10 minWrite a function that multiplies price by quantity. Show 25 x 4.
- 5
Reuse one function
medium10 minUse one area function for a square of side 3 and one of side 7, and add the answers.
Find the bug(5)
- 1
Fix the function that is never called
easy8 minThe function is defined but nothing runs it.
- 2
Fix the missing brackets
easy8 minWithout brackets the function itself is shown, not its result.
- 3
Fix the missing return
easy8 minThe function calculates but never sends the answer back.
- 4
Fix the wrong operator
easy8 minThe function adds when it should multiply.
- 5
Fix the hard-coded value
easy8 minThe 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