Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Arrays Intro
Making Arrays
Array Builder Kata
Array Elements
Human Names Kata
Array Length
Longest Array Kata
Looping Over Arrays
Highest Number Kata
Word Hunter Kata
Array Average Kata
Min-Max Kata
Adding Elements
Number Range Kata
Removing Elements
Arrays of Objects
Biggest Animal Kata
Arrays of Arrays
Taboo Words Kata
Going Further
Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Arrays Intro
Making Arrays
Array Builder Kata
Array Elements
Human Names Kata
Array Length
Longest Array Kata
Looping Over Arrays
Highest Number Kata
Word Hunter Kata
Array Average Kata
Min-Max Kata
Adding Elements
Number Range Kata
Removing Elements
Arrays of Objects
Biggest Animal Kata
Arrays of Arrays
Taboo Words Kata
Going Further
Modulus and Remainders
If we want to get the remainder of a division operation, we can use the modulo operator (%
). Try it:
5 % 2
The result is 1
.
Remainder Refresher
5
divided by 2
is exactly 2.5
. If we are dividing using only whole numbers, then the answer would be 2
instead.
Think of it this way. If we have 5 pennies and split them into two even piles, each pile would have 2 pennies and there would be 1 penny left over. That is the remainder.
Learning Goals
I can use the modulo operator to get the remainder after division
Code Editor
Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.
Console Output
// Console output will appear here...
0 output lines