JavaScript Type Conversion — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Type Conversion 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
Convert text to a number
easy10 minConvert the text and add eight to it.
- 2
Convert a number to text
easy10 minConvert a number to a string and report its type.
- 3
Convert to a boolean
easy10 minReport what Boolean gives for an empty string.
- 4
Handle a failed conversion
easy10 minReport a message when the text cannot become a number.
- 5
Add two form values
medium10 minConvert both inputs before adding them.
Find the bug(5)
- 1
Fix the values joined instead of added
easy8 minText values join with plus rather than adding.
- 2
Fix the conversion applied too late
easy8 minThe join has already happened before the conversion.
- 3
Fix the failed conversion unchecked
easy8 minA failed conversion gives NaN, which must be checked for.
- 4
Fix toString called on null
easy8 minString works on null, but toString throws.
- 5
Fix the empty string assumed to be NaN
easy8 minNumber of an empty string is 0, not NaN.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace