Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
βΆ Do the exercisesExercise 1 β Which operator for remainder?
Which operator gives you the remainder of a division?
%/**//Hint : Think about which arithmetic operator is specifically designed to give you the remainder, not the quotient.
Exercise 2 β Triple a value
Complete the code to triple Aquachu's power using a compound operator:
Hint : Compound operators let you modify a variable based on its current value in a shorter way.
Exercise 3 β Predicting Math.floor()
What is the result of Math.floor(18.9)?
181918.920Hint : Remember the difference between Math.floor() and Math.round() - one always goes in a specific direction.
Exercise 4 β Match the operation
Match each code with its result:
10 + 510 - 510 * 510 / 5155502Exercise 5 β Identifying NaN
Which of these operations will produce NaN?
0 / 010 / 010 / 210 * 0Hint : NaN appears when a math operation produces an undefined result. Which operation is mathematically impossible?
Exercise 6 β Finding the maximum
Complete the code to find the highest score among three CodΓ©mons:
Hint : The Math object has methods to compare values. Think about what the opposite of minimum is.
Exercise 7 β Understanding exponentiation
What is the result of 2 ** 4?
168624Hint : Exponentiation means multiplying a number by itself multiple times. Count how many times carefully.
Exercise 8 β Rounding with Math.round()
What does Math.round(7.4) return?
787.47.5Hint : Math.round() looks at the decimal part to decide which way to round. What's the rule for values below 0.5?
Exercise 9 β Using the modulo operator
Complete the code to find the remainder when 17 is divided by 5:
Hint : You need an operator that gives the remainder, not the result of the division itself.
Exercise 10 β Compound assignment result
What will be the value of x after this code?
let x = 100;
x /= 4;
console.log(x);2510496400Hint : Compound assignment operators modify the variable in place. Think about what operation is being performed.
Exercise 11 β Match Math methods
Match each Math method with its purpose:
Math.random()Math.min()Math.floor()Math.round()Exercise 12 β Understanding Infinity
What is the result of 100 / 0?
InfinityNaN0100Hint : Division by zero doesn't cause an error in JavaScript. It produces one of the special numeric values you've learned.
Exercise 13 β Order of operations
What number completes this code to make result equal to 20?
Hint : Order of operations matters! Multiplication is calculated before addition. Work backwards from the expected result.
Exercise 14 β Sequential operations
What is the final value of energy?
let energy = 50;
energy += 20;
energy *= 2;
energy -= 30;
console.log(energy);110809070Hint : Compound operators are executed in sequence, from top to bottom. Track the value after each operation.
Exercise 15 β Understanding Math.random() range
Which statement about Math.random() is TRUE?
Hint : Pay attention to the terms 'inclusive' and 'exclusive' when describing ranges. They tell you about the boundaries.
Exercise 16 β Random integer from 0 to 9
Complete the code to generate a random integer from 0 to 9:
Hint : Count how many different values are possible in the desired range. That's your multiplier.
Exercise 17 β Pick the right Math tool
Match each piece of code with the job it does in a CodΓ©mon game:
Math.min(hp, 100)Math.max(hp, 0)Math.floor(Math.random() * 5)Math.round(87.6)Exercise 18 β The type of NaN
What does this code display?
let result = 0 / 0;
console.log(typeof result);"number""NaN""undefined""string"Hint : Two of these options are not even types that typeof can return. For the rest, think about what kind of operation produced this value in the first place.
Exercise 19 β Checking for NaN
Complete the code to check if result is NaN:
Hint : There's a special function to check for NaN. It's part of the Number object and uses dot notation.
Exercise 20 β Which expression gives 30?
Which of these expressions gives 30?
(5 + 5) * 35 + 5 * 35 * 5 + 35 + 3 * 5Hint : The same three numbers appear everywhere, so only the order in which JavaScript reaches them changes. Work each option out step by step.
Exercise 21 β Finding minimum value
What does Math.min(45, 23, 67, 12, 89) return?
12234589Hint : This Math method compares all the values. Think about what 'min' might stand for.
Exercise 22 β Squaring with compound operator
Complete the code to square the value of damage (multiply it by itself):
Hint : Squaring involves multiplication with a specific power. There's a compound operator for exponentiation.
Exercise 23 β Match special number values
Match each operation with the special value it produces:
Math.sqrt(-16)50 / 0-100 / 00 / 0NaNInfinity-InfinityNaNExercise 24 β Combining Math methods
What is the result of this code?
let a = 12.7;
let b = 12.3;
let result = Math.max(Math.round(a), Math.round(b));
console.log(result);131212.712.3Hint : Functions are evaluated from the inside out. What happens to each value first, before comparing them?
Exercise 25 β Checking for finite numbers
Complete the code to check if score is a finite number (not Infinity and not NaN):
Hint : There's a Number method that checks if a value is neither infinite nor invalid. Look for the opposite of 'infinite'.