Math
JavaScript · Unit 17: What JavaScript brings along
- Full plan
- JavaScript
- 11 exercises
Math is a toolbox of number helpers that comes with the language. You already know Math.floor(), which always goes down, and Math.round(), which goes to the closest whole number.
Here's the third one: Math.ceil() always climbs to the next whole number, even if the decimal is tiny.
console.log(Math.ceil(4.1));
console.log(Math.floor(4.9));
console.log(Math.round(4.5));Prints
5 4 5
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Complete the code
Each table seats 4 people. Fill in the blank to work out how many tables 13 people need.
3. Predict the output
The temperature dropped below zero. What does it print?
4. Put the lines in order
Put
boxes(items)in order: how many boxes of 12 items you need to store them all.5. Predict the output
What does this code print?
6. Find the bug
gapshould tell how many degrees there are between two temperatures, no matter which one is bigger: both calls should print 12. Which line has the error?7. Predict the output
What does this code print?
8. Multiple choice
What does
sidework out?9. Predict the output
This is how you roll a 6-sided die. What does it print?
10. Multiple choice
You want a random whole number from 1 to 10, with all ten coming up equally often. Which one does that?
11. Complete the code
Fill in the blank to print the highest grade in the class.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.