Report the absolute value of minus five.
Acceptance criteria
- 1.#out should show 5.
JavaScript Tutorial · JavaScript Numbers & Math
These 10 tasks go with the JavaScript Math Object 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: “Math is a built-in object holding mathematical constants and functions.” .
1.Remove the signexercise · easy · 10 min
Report the absolute value of minus five.
Passes when: #out should show 5.
2.Find a square rootexercise · easy · 10 min · practice plan
Report the square root of 144.
Passes when: #out should show 12.
3.Raise to a powerexercise · easy · 10 min · practice plan
Use Math.pow to report two to the tenth.
Passes when: #out should show 1024.
4.Measure a distanceexercise · easy · 10 min · practice plan
Report how far apart three and eight are.
Passes when: #out should show 5.
5.Work out a circle areaexercise · medium · 10 min · practice plan
Report the rounded area of a circle of radius three.
Passes when: #out should show 28.
6.Fix Math used with newbug fix · easy · 8 min
Math is not a constructor.
Passes when: #out should show 5.
7.Fix the missing Math prefixbug fix · easy · 8 min · practice plan
sqrt is a method of Math, not a global function.
Passes when: #out should show 12.
8.Fix the distance without absbug fix · easy · 8 min · practice plan
The difference is negative, so the sign must be removed.
Passes when: #out should show distance 5.
9.Fix PI written by handbug fix · easy · 8 min · practice plan
Use the built-in constant rather than a rough value.
Passes when: #out should show 28.
10.Fix the arguments to pow swappedbug fix · easy · 8 min · practice plan
The base comes first and the exponent second.
Passes when: #out should show 1024.
Between them these tasks cover Math, abs and sqrt.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.