Quizz

The full text of this chapter, to read or revisit. To practise, do the exercises.

β–Ά Do the exercises

Exercise 1 β€” Which operator for remainder?

Which operator gives you the remainder of a division?

Options
β€’ %
β€’ /
β€’ **
β€’ //

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)?

Options
β€’ 18
β€’ 19
β€’ 18.9
β€’ 20

Hint : 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:

Items to match
β€’ 10 + 5
β€’ 10 - 5
β€’ 10 * 5
β€’ 10 / 5
Definitions
β€’ 15
β€’ 5
β€’ 50
β€’ 2

Exercise 5 β€” Identifying NaN

Which of these operations will produce NaN?

Options
β€’ 0 / 0
β€’ 10 / 0
β€’ 10 / 2
β€’ 10 * 0

Hint : 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?

Options
β€’ 16
β€’ 8
β€’ 6
β€’ 24

Hint : 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?

Options
β€’ 7
β€’ 8
β€’ 7.4
β€’ 7.5

Hint : 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);
Options
β€’ 25
β€’ 104
β€’ 96
β€’ 400

Hint : 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:

Items to match
β€’ Math.random()
β€’ Math.min()
β€’ Math.floor()
β€’ Math.round()
Definitions
β€’ Generate random decimal between 0 and 1
β€’ Find the smallest value
β€’ Round down to nearest integer
β€’ Round to nearest integer

Exercise 12 β€” Understanding Infinity

What is the result of 100 / 0?

Options
β€’ Infinity
β€’ NaN
β€’ 0
β€’ 100

Hint : 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);
Options
β€’ 110
β€’ 80
β€’ 90
β€’ 70

Hint : 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?

Options
β€’ It can be 0 but never 1
β€’ It can be 1 but never 0
β€’ It can be both 0 and 1
β€’ It can never be 0 or 1

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:

Items to match
β€’ Math.min(hp, 100)
β€’ Math.max(hp, 0)
β€’ Math.floor(Math.random() * 5)
β€’ Math.round(87.6)
Definitions
β€’ Stop HP from ever going above 100
β€’ Stop HP from ever going below 0
β€’ Pick a random whole number from 0 to 4
β€’ Show a decimal HP as the closest whole number

Exercise 18 β€” The type of NaN

What does this code display?

let result = 0 / 0; console.log(typeof result);
Options
β€’ "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?

Options
β€’ (5 + 5) * 3
β€’ 5 + 5 * 3
β€’ 5 * 5 + 3
β€’ 5 + 3 * 5

Hint : 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?

Options
β€’ 12
β€’ 23
β€’ 45
β€’ 89

Hint : 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:

Items to match
β€’ Math.sqrt(-16)
β€’ 50 / 0
β€’ -100 / 0
β€’ 0 / 0
Definitions
β€’ NaN
β€’ Infinity
β€’ -Infinity
β€’ NaN

Exercise 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);
Options
β€’ 13
β€’ 12
β€’ 12.7
β€’ 12.3

Hint : 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'.

Back to the course