Advertisement
Aliendreamer

gcs

Jan 24th, 2019
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function greatestCD() {
  2.    
  3.    let inputA=+document.getElementById("num1").value;
  4.    let inputB=+document.getElementById("num2").value;
  5.    let resultDiv=document.getElementById("result");
  6.    
  7.       a = Math.abs(inputA);
  8.       b = Math.abs(inputB);
  9.       let divisor=GetDivisor(a,b);
  10.    
  11.       resultDiv.textContent=divisor;
  12.  
  13.       function GetDivisor(a,b){
  14.            
  15.       if (b > a) {var temp = a; a = b; b = temp;}
  16.       while (true) {
  17.           if (b == 0) return  a;
  18.           a %= b;
  19.           if (a == 0) return b;          
  20.           b %= a;
  21.          
  22.       }  
  23.    }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement