Home / Common DenominAtors
Common Denomintors
Write a function that calculates the greatest common denominator of the first and second parameters.
Function Scaffolding
/**
* Calculates the greatest common denominator (GCD) of two numbers.
*
* @param {number} a - The first number.
* @param {number} b - The second number.
* @returns {number} The greatest common denominator of a and b.
*/
function getGCD(a, b) {
// ...
}
Possible Approach
- Create a function with one parameter. Have the function console.log() the input.
- Determine which variable is smaller.
- Create a loop that iterates through the smaller value starting with the number down to one.
- Write an if statement that check if both numbers are divisible by the counter.
- If both are divisible, return the counter.
Assets
Download PDF Slide Desk