Branches and loops

Count the multiples of 3 between 1 and the given limit, inclusive.

Examples

Example 1

Input
10
Expected output
3

Example 2

Input
2
Expected output
0

Hints and solution

Hint 1

Use the remainder operator and compare it with zero.

Reveal worked answer

Maintain a counter of qualifying numbers and increment it whenever number % 3 === 0. The three matches up to 10 are 3, 6 and 9.

Back to the lesson