DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Loops and conditions
hannaA
hannaA

Posted on

Loops and conditions

Request two numbers and find only their largest common divisor

let numberOne = prompt("input the first number");
let numberTwo = prompt("input the second number");
let smaller = 0;
let bigger = 0; 
let LCD = 0;

if (numberOne > numberTwo) {
    smaller = numberTwo;
    bigger = numberOne;
} else {
    smaller = numberOne;
    bigger = numberTwo;
}

for (let i = 0; i <= smaller; i++) {
    if (smaller % i === 0 && bigger % i === 0) {
        LCD = i;
        console.log("LCD", LCD);
    }
}


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

"I made 10x faster JSON.stringify() functions, even type safe"

☝️ Must read for JS devs