Playing with JavaScript Adding & Dividing Numbers using JavaScript

Playing with JavaScript Adding & Dividing numbers using JavaScript.

  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4.      <body>  
  5.           <p id="demo"></p>  
  6.           Enter Number One<input type="text" name="no1" id="1"><br>  
  7.           Enter Number Two<input type="text" name="no2" id="2"><br>  
  8.           <button onclick="myadd()">Press</button>  
  9.           <p id="dem"></p>  
  10.           <script>  
  11.           function myadd() {  
  12.                var y = document.getElementById("1");  
  13.                var x = document.getElementById("2");  
  14.                var a = y.value;  
  15.                var b = x.value;  
  16.                if (a == "") {  
  17.                     alert("Please Enter No 1");  
  18.                     return  
  19.                }  
  20.                if (b == "") {  
  21.                     alert("Please Enter No 2");  
  22.                     return  
  23.                }  
  24.                if (a == b) {  
  25.                     alert("No cannot be Same");  
  26.                     return  
  27.                } else {  
  28.                     var c = parseInt(a) + parseInt(b);  
  29.                     document.getElementById("demo").innerHTML = "On Adding" + c;  
  30.                     var e = parseInt(b) / parseInt(a);  
  31.                     document.getElementById("dem").innerHTML = "On Division" + e;  
  32.                }  
  33.           }  
  34.           </script>  
  35.      </body>  
  36.   
  37. </html>