Report the biggest of five, two and nine.
Acceptance criteria
- 1.#out should show 9.
JavaScript Tutorial · JavaScript Numbers & Math
These 10 tasks go with the JavaScript Math.min and Math.max 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.min and Math.max find the smallest and largest of the values you give them.” .
1.Find the largest of threeexercise · easy · 10 min
Report the biggest of five, two and nine.
Passes when: #out should show 9.
2.Find the largest in an arrayexercise · easy · 10 min · practice plan
Spread the scores to find the highest.
Passes when: #out should show 91.
3.Find the smallest in an arrayexercise · easy · 10 min · practice plan
Spread the scores to find the lowest.
Passes when: #out should show 30.
4.Clamp a valueexercise · easy · 10 min · practice plan
Keep 150 inside the range zero to one hundred.
Passes when: #out should show 100.
5.Guard an empty arrayexercise · medium · 10 min · practice plan
Report a message rather than spreading an empty array.
Passes when: #out should show nothing to compare.
6.Fix the array passed directlybug fix · easy · 8 min
Math.max takes separate arguments, not an array.
Passes when: #out should show 91.
7.Fix min used where max belongsbug fix · easy · 8 min · practice plan
The highest score is wanted, not the lowest.
Passes when: #out should show 91.
8.Fix the clamp the wrong way roundbug fix · easy · 8 min · practice plan
With the calls swapped a value below the range comes back as the maximum.
Passes when: #out should show clamped to 0.
9.Fix the unguarded empty arraybug fix · easy · 8 min · practice plan
Spreading an empty array gives -Infinity from max.
Passes when: #out should show nothing to compare.
10.Fix sort used to find the largestbug fix · easy · 8 min · practice plan
The default sort compares as text, so it puts 91 last rather than 100.
Passes when: #out should show 100.
Between them these tasks cover Math.max, Spread and Clamping.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.