LESSON 11 OF 50

Calculate a remainder

Use the % operator to obtain the remainder of a division.

Official sourceECMAScript — multiplicative operatorsReviewed: 2026-08-26
STEP 1 · LEARN

How it works

The % operator returns the remainder after dividing the first number by the second. For 17 and 5, the integer quotient is 3 and the remainder is 2.

Correct example
const rest = 17 % 5;
console.log(rest);

The expression produces 2, which is stored in the rest constant.

Common mistake
const rest = 17 / 5;
console.log(rest);

The / operator calculates the quotient 3.4, not the remainder.

STEP 2 · APPLY

Your exercise

Declare rest as 17 % 5 and print the variable.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • rest is declared with const.
  • The rest initializer uses 17 % 5.
  • The output is 2.
Explain the solution logic

The operator is applied to the required values, and the output confirms the real result.