Convert the text and add eight to it.
Acceptance criteria
- 1.#out should show 50.
JavaScript Tutorial · JavaScript Type System
These 10 tasks go with the JavaScript Type Conversion chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Type conversion changes a value from one type to another on purpose.” .
1.Convert text to a numberexercise · easy · 10 min
Convert the text and add eight to it.
Passes when: #out should show 50.
2.Convert a number to textexercise · easy · 10 min · practice plan
Convert a number to a string and report its type.
Passes when: #out should show string.
3.Convert to a booleanexercise · easy · 10 min · practice plan
Report what Boolean gives for an empty string.
Passes when: #out should show empty is falsy.
4.Handle a failed conversionexercise · easy · 10 min · practice plan
Report a message when the text cannot become a number.
Passes when: #out should show not a number.
5.Add two form valuesexercise · medium · 10 min · practice plan
Convert both inputs before adding them.
Passes when: #out should show 25.
6.Fix the values joined instead of addedbug fix · easy · 8 min
Text values join with plus rather than adding.
Passes when: #out should show 25.
7.Fix the conversion applied too latebug fix · easy · 8 min · practice plan
The join has already happened before the conversion.
Passes when: #out should show 50.
8.Fix the failed conversion uncheckedbug fix · easy · 8 min · practice plan
A failed conversion gives NaN, which must be checked for.
Passes when: #out should show not a number.
9.Fix toString called on nullbug fix · easy · 8 min · practice plan
String works on null, but toString throws.
Passes when: #out should show null.
10.Fix the empty string assumed to be NaNbug fix · easy · 8 min · practice plan
Number of an empty string is 0, not NaN.
Passes when: #out should show zero.
Between them these tasks cover Number, String and Boolean.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.