JavaScript Program to find Common Divisors

You are Here:

What are Common Divisors?

A number that divides two or more numbers without remainder.

Tips: It is recommended to use our online common divisor calculator for better understanding.

Examples

The following table provides few examples of common divisors of the given numbers.

NumbersCommon Divisors
4, 61, 2
12, 241, 2, 3, 4, 6, 12
15, 25, 501, 5

Common Divisors of Two Numbers

In the following example, we will find the common divisors of numbers 12 and 24.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <h1>JS Common Divisors</h1> <script> var num1 = 12; var num2 = 24; var txt = ""; min = (num1 < num2) ? num1 : num2; document.write("Common Divisors of "+num1+" and "+num2); for(i=1; i<=min; i++) { if( num1 % i == 0 && num2 % i == 0 ) txt += i +", "; } document.write("<br>" +txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author