Navigate back to the homepage

How to check if a number is divisible by another number in javascript?

Infinitbility
JavaScript
June 5th, 2022 · 1 min read

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.

1const inputNum = 15;
2
3if (inputNum % 3 == 0) {
4 console.log('✅ input number divisible');
5} else {
6 console.log('⛔️ input number not divisible');
7}

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 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to check if a number is between two values in javascript?

Example of check if a number is between two values in javascript with step by step guide.

June 4th, 2022 · 1 min read

Guide to use onflow flow-js-testing framework

Example of use onflow flow-js-testing framework with step by step guide.

June 3rd, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]