function gcd(a,b){ let hcf; for (let i = 1; i <= a && i <= b; i++) { // check if is factor of both integers if( a % i == 0 && b % i == 0) { hcf = i; } } return hcf; } gcd(6, 15);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter