Skip to main content

Command Palette

Search for a command to run...

[JavaScript] Numbers, Dates, Intl, and Timers - The Remainder Operator

Published
•View as Markdown
[JavaScript] Numbers, Dates, Intl, and Timers - The Remainder Operator
// Remainder Operator
console.log(5 % 2);
console.log(5 / 2); // 5 = 2 * 2 + 1

console.log(8 % 3);
console.log(8 / 3); // 8 = 2 * 3 + 2

console.log(6 % 2);
console.log(6 / 2); // 6 = 3 * 2

console.log(7 % 2);
console.log(7 / 2); // 7 = 3 * 2 + 1

const isEven = n => n % 2 === 0;
console.log(isEven(8));
console.log(isEven(23));
console.log(isEven(514));

labelBalance.addEventListener('click', function () {
  [...document.querySelectorAll('.movements__row')].forEach(function (row, i) {
    // every N time
    if (i % 2 === 0) row.style.backgroundColor = 'orangered';
    if (i % 3 === 0) row.style.backgroundColor = 'blue';
  });
});

the remainder operator 1.PNG

the remainder operator 2.PNG

JavaScript

Part 1 of 50

More from this blog

Jayden's Blog

166 posts