JavaScript Default Parameters — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Default Parameters 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
Add a default
easy10 minGive a greeting function a default name of friend and call it with no argument.
- 2
Override the default
easy10 minCall the same greeting function with the name Ada.
- 3
A default quantity
easy10 minGive quantity a default of 1 and show the total for a price of 50.
- 4
Build a default from another parameter
easy10 minMake height default to width so one argument gives a square. Show it for 6.
- 5
A default empty array
medium10 minDefault the list to an empty array so counting never fails. Show the count with no argument.
Find the bug(5)
- 1
Fix the missing default
easy8 minWith no default the name becomes undefined.
- 2
Fix the colon used instead of equals
easy8 minA default is written with an equals sign.
- 3
Fix the default that is never used
easy8 minPassing null does not trigger the default.
- 4
Fix the default in the wrong place
easy8 minThe default is on the first parameter, so the value lands wrongly.
- 5
Fix the default that crashes
easy8 minWithout a default the length of undefined cannot be read.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace