let k = 1, a = 20, b = 30; for (let i = 2; i <= b && i <= a; ) { if(!(b % i) && !(a % i) ) { b /= i; a /= i; k *= i; } else i++ } alert(k);