// 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);Calculate Greatest Common Divisor (GCD) of Two Numbers
javascript
Related Posts
More content you might like
Tutorial
javascript
Running JavaScript in the Browser Console
- Arrow keys: Navigate through previous commands.
Shift+Enter: Write multi-line code.
- The console displays detailed error messages to help debug code.
Dec 10, 2024
Read More Tutorial
javascript
Mastering console.log Advanced Usages and Techniques
Example with console.groupCollapsed:
console.groupCollapsed('User Details');
console.log('Name: Alice');
console.log('Age: 30');
console.log('Active: true');
console.groupEnd();Sep 02, 2024
Read More Code
javascript
Parse JSON String to Object
No preview available for this content.
Jan 26, 2024
Read More Code
javascript
Validate Password Strength
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!