Playing with JavaScript Adding & Dividing Numbers using JavaScript

Playing with JavaScript Adding & Dividing numbers using Java Script.

<!DOCTYPE html>
<html>
<
body>
<
p id="demo"></p>
Enter Number One<input type="text" name="no1" id="1"><br>
Enter Number Two<input type="text" name="no2" id="2"><br>
<button onclick="myadd()">Press</button>
<p id="dem"></p>
<script>
    function myadd() {
        var y = document.getElementById("1");
        var x = document.getElementById("2");
        var a = y.value;
        var b = x.value;
        if (a == "") {
            alert("Please Enter No 1");
           
return
        }
        if (b == "") {
            alert("Please Enter No 2");
           
return
        }
        if (a == b) {
            alert("No cannot be Same");
           
return
        }
        else {
            var c = parseInt(a) + parseInt(b);
            document.getElementById("demo").innerHTML = "On Adding" + c;
            var e = parseInt(b) / parseInt(a);
            document.getElementById("dem").innerHTML = "On Division" + e;
        }
    }
</script> 
</body>
</
html>

Ebook Download
View all
Learn
View all