// Function to calculate the GCD of two numbers using the Euclidean Algorithm
function calculateGCD(a, b) {
while (b !== 0) {
const temp = b;
b = a % b;
a = temp;
}
return a;
}
// Calculate and log the GCD of two numbers (e.g., 48 and 18)
const gcd = calculateGCD(48, 18);
console.log('GCD of Two Numbers:', gcd);
code
Calculate Greatest Common Divisor (GCD) of Two Numbers
This JavaScript code defines a function calculateGCD that uses the Euclidean Algorithm to calculate the Greatest Common Divisor (GCD) of two numbers. The GCD is then calculated for the example numbers 48 and 18, and the result is logged to the console.
Console.log
GCD
Greatest Common Divisor
Euclidean Algorithm