JavaScript Truthy and Falsy — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Truthy and Falsy 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
Test a non-empty string
easy10 minReport whether a piece of text is truthy.
- 2
Test an empty array
easy10 minReport that an empty array is still truthy.
- 3
Check a list properly
easy10 minUse length to find out whether the array is empty.
- 4
Test the string zero
easy10 minReport whether the text zero is truthy.
- 5
Convert deliberately
medium10 minUse Boolean to report the truthiness of an empty string.
Find the bug(5)
- 1
Fix the empty array check
easy8 minAn empty array is truthy, so length must be checked.
- 2
Fix the zero treated as missing
easy8 minA count of zero is valid and should be reported.
- 3
Fix the empty object check
easy8 minAn empty object is truthy, so its keys must be counted.
- 4
Fix the string zero assumed falsy
easy8 minThe text zero is truthy, unlike the number.
- 5
Fix the valid zero rejected
easy8 minA guest id of zero is valid, but a truthy check treats it as missing.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace