Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To check if a number is divisible by another number, use the remainder ( % ) operator if get 0 means the number is divisible else not.

Note: Here, another number is any number like 3, 4, 5, 6, 7, 8, etc.

Today, I’m going to show How do I check if a number is divisible by another number in javascript, here I will use the modulo ( % ) operator and if... else statements to check if a number is divisible by another number or not.

Let’s start the today’s tutorial How do you check if a number is divisible by another number in javascript?

In the following example, we are going to do the number is a divisible 3 or not.

If the input number is divisible by 3 we will log input number divisible else input number not divisible.

let’s write the code.

const inputNum = 15;

if (inputNum % 3 == 0) {
  console.log('âś… input number divisible');
} else {
  console.log('⛔️ input number not divisible');
}

In the above program, we have use 15 as input number, after that we check it’s divisible by 3 or not.

let’s check the output.

javascript, check if a number is divisible by another number example
javascript, check if a number is divisible by another number or not example

I hope it’s help you, All the best 👍.