Why does it always display "undefined" when I run this html?
This program is used for finding the grand common divisor. Could anyone tell me what is the problem with it? <!DOCTYPE HTML> <html> <head> <title>GCD</title> <script type="text/javascript"> function result(){ var a=document.getElementById("first"); var b=document.getElementById("second"); var o=Math.min(a,b); var j=Math.abs(o); var im=count(j); var c=document.getElementById("third"); c.innerHTML=im; } function count(j){ var il; for(var x=1;x<=j;++x){ var l=x; if(a%l==0&&b%l==0){ il=0; il+=l; } } return il; } </script> </head> <body> <p>First Number</p> <br/> <input type="number" id="first"/> <br/Second Number</p> <br/> <input type="number" id="second"/> <br/> <button onclick="result()"> OK </button> <br/> <p id="third"></p> </body> </html>