Loops and conditions

July 31, 2022


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);
    }
}




Source link

Comments 0

Leave a Reply

Your email address will not be published. Required fields are marked *