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.

`.css-1chxjt6{position:absolute;right:22px;top:24px;padding:8px 12px 7px;border-radius:5px;color:#6f7177;-webkit-transition:background 0.3s ease;transition:background 0.3s ease;}.css-1chxjt6:hover{background:rgba(255,255,255,0.07);}.css-1chxjt6[data-a11y="true"]:focus::after{content:"";position:absolute;left:-2%;top:-2%;width:104%;height:104%;border:2px solid var(--theme-ui-colors-accent,#6166DC);border-radius:5px;background:rgba(255,255,255,0.01);}@media (max-width:45.9375em){.css-1chxjt6{display:none;}}1const inputNum = 15;23if (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.

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.

Request New Tutorial or Article on mail [email protected]

### Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

### 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