Author -  Sai gowtham

Check if a number is multiple of another number in JavaScript

In this tutorial, we are going to learn about how to check if a number is multiple of another number in JavaScript with the help of examples.

Consider, we have a following number:

const num = 10

To find if a above number 10 is a multiple of another number, we should divide the first number by second and get the remainder 0 then only we call it’s a multiple of another number otherwise it is not a multiple.

For example: 10%2 = 0

Using the % Modulo operator

To check if a number is a multiple of another number, we can use the % modulo operator in JavaScript.

The modulo % operator returns the remainder of first number by second number eg: 10 % 2 = 0, so if we get a remainder 0 then the given number is a multiple of another number otherwise it not a multiple.

Here is an example:

const num = 10;

if (num % 2 === 0) {
  console.log("10 is a multiple of 2");
}else {
  console.log("10 is not a multiple of 2");
}

Output:

"10 is a multiple of 2"

In the above code we have added 10 % 2 === 0 in if condition. so if 10 is divided by 2 and returns the remainder 0 then it prints the output “10 is a multiple of 2”.

Example 2 :

if (20 % 2 == 0) {
  console.log("20 is a multiple of 2");
}else {
  console.log("20 is not multiple of 2");
}

Output:

"20 is a multiple of 2"

Checking if a number is not multiple of another

To check if a number is not a multiple of another number, we can use the modulo operator % but the remainder of first number by second number is not equal to 0.

Here is an example:

if (35 % 2 != 0){
    console.log("35 is not a multiple of 2");
}

In the above code, 35 is divided by 2 and returns the remainder 5. So 35 is not multiple of 2.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY