Report what a string plus a number gives.
Acceptance criteria
- 1.#out should show 53.
JavaScript Tutorial · JavaScript Type System
These 10 tasks go with the JavaScript Type Coercion 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 coercion is JavaScript converting types automatically, whether you wanted it or not.” .
1.See plus joinexercise · easy · 10 min
Report what a string plus a number gives.
Passes when: #out should show 53.
2.See minus convertexercise · easy · 10 min · practice plan
Report what a string minus a number gives.
Passes when: #out should show 2.
3.Watch the order matterexercise · easy · 10 min · practice plan
Report the result of 1 plus 2 plus the text 3.
Passes when: #out should show 33.
4.Convert a booleanexercise · easy · 10 min · practice plan
Report what true plus one gives.
Passes when: #out should show 2.
5.Avoid the surpriseexercise · medium · 10 min · practice plan
Convert before adding so the answer is arithmetic.
Passes when: #out should show 15.
6.Fix the accidental joinbug fix · easy · 8 min
The values are being joined instead of added.
Passes when: #out should show 15.
7.Fix the order of operationsbug fix · easy · 8 min · practice plan
The numbers should be added before the text is joined.
Passes when: #out should show 33.
8.Fix the total built as textbug fix · easy · 8 min · practice plan
Starting with an empty string joins every number.
Passes when: #out should show 60.
9.Fix the boolean used as textbug fix · easy · 8 min · practice plan
The boolean should be counted as a number.
Passes when: #out should show 2.
10.Fix the comparison of mixed typesbug fix · easy · 8 min · practice plan
Convert the text before comparing it as a number.
Passes when: #out should show bigger.
Between them these tasks cover Coercion, Plus operator and Implicit conversion.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.