Report the types of a string and a number.
Acceptance criteria
- 1.#out should show string number.
JavaScript Tutorial · JavaScript Errors
These 10 tasks go with the JavaScript Debugging 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: “Debugging is the process of finding out why code does not do what you expected.” .
1.Check the typesexercise · easy · 10 min
Report the types of a string and a number.
Passes when: #out should show string number.
2.Spot the type mismatchexercise · easy · 10 min · practice plan
Report whether the two values are strictly equal.
Passes when: #out should show different types.
3.Label what you printexercise · easy · 10 min · practice plan
Build a labelled report of the width and area.
Passes when: #out should show width 4 area 20.
4.Narrow down a pipelineexercise · easy · 10 min · practice plan
Report the value after each stage of the transformation.
Passes when: #out should show doubled 2,4,6 kept 6.
5.Find the wrong assumptionexercise · medium · 10 min · practice plan
Convert the value before adding, and report the total.
Passes when: #out should show 12.
6.Fix the values compared without checking typesbug fix · easy · 8 min
The two look identical when printed but are different types.
Passes when: #out should show different types.
7.Fix the unlabelled outputbug fix · easy · 8 min · practice plan
Bare values give no clue which is which.
Passes when: #out should show width 4 area 20.
8.Fix the silent joining bugbug fix · easy · 8 min · practice plan
The price is text, so plus joins instead of adding.
Passes when: #out should show 12.
9.Fix the wrong filter boundarybug fix · easy · 8 min · practice plan
The pipeline keeps the wrong values, which printing each stage reveals.
Passes when: #out should show doubled 2,4,6 kept 6.
10.Fix the type read from the valuebug fix · easy · 8 min · practice plan
Printing the value alone does not reveal its type.
Passes when: #out should show string number.
Between them these tasks cover Debugging, typeof checks and Narrowing down.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.