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
Declare a function
easy10 minDeclare a function named square and show square of 9.
- 2
Call before the declaration
easy10 minCall a declared function on a line above it and show the answer for 7.
- 3
Two parameters
easy10 minDeclare a function that joins a first and last name with a space.
- 4
No parameters
easy10 minDeclare a function that takes nothing and returns the word Ready.
- 5
Branch inside a function
medium10 minDeclare a function returning Adult for 18 or over, Minor otherwise. Show the answer for 15.
Find the bug(5)
- 1
Fix the misspelled keyword
easy8 minThe keyword is function, spelled in full.
- 2
Fix the duplicate declaration
easy8 minThe later declaration replaces the first one.
- 3
Fix the swapped parameters
easy8 minThe names come back in the wrong order.
- 4
Fix the missing space
easy8 minThe two names run together with no gap.
- 5
Fix the inverted condition
easy8 minThe 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