Report four point five rounded.
Acceptance criteria
- 1.#out should show 5.
JavaScript Tutorial · JavaScript Numbers & Math
These 10 tasks go with the JavaScript Math Rounding 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: “round, floor, ceil and trunc turn a decimal into a whole number in different ways.” .
1.Round to the nearestexercise · easy · 10 min
Report four point five rounded.
Passes when: #out should show 5.
2.Always round downexercise · easy · 10 min · practice plan
Report four point nine rounded down.
Passes when: #out should show 4.
3.Always round upexercise · easy · 10 min · practice plan
Report four point one rounded up.
Passes when: #out should show 5.
4.Count the pages neededexercise · easy · 10 min · practice plan
Work out how many pages hold 23 items at ten per page.
Passes when: #out should show 3.
5.Round to two decimalsexercise · medium · 10 min · practice plan
Round pi to two decimal places as a number.
Passes when: #out should show 3.14.
6.Fix floor used for pagesbug fix · easy · 8 min
Rounding down loses the last partial page.
Passes when: #out should show 3.
7.Fix the negative rounded wronglybug fix · easy · 8 min · practice plan
floor goes further down on a negative; trunc just cuts.
Passes when: #out should show cut to -4.
8.Fix the decimal roundingbug fix · easy · 8 min · practice plan
Multiply before rounding, then divide back.
Passes when: #out should show 3.14.
9.Fix ceil used where floor belongsbug fix · easy · 8 min · practice plan
Whole units should round down, not up.
Passes when: #out should show 4.
10.Fix toFixed used where a number is neededbug fix · easy · 8 min · practice plan
toFixed returns a string, so the arithmetic joins instead.
Passes when: #out should show 8.
Between them these tasks cover round, floor and ceil.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.