Now let's see the Two Number Addition of JavaScript.
To do this, first download the jquery-2.2.0.min.js file.
Then copy and run the Example code given below.
Practices of this code:
<!DOCTYPE html>
<html>
<body>
<h1>Two Number Addition</h1>
Number 1 <input id="txt1" type="text" value="">
<br>
<br>
Number 2 <input id="txt2" type="text" value="">
<br>
<br>
(Number 1 + Number 2)
<input type="button" value="Check Answer" onclick="chk_ans();">
<script src="jquery-2.2.0.min.js"></script>
<script>
function chk_ans()
{
/*parseInt is used convert to Integer value, text box is return string value*/
var txt1 = parseInt($("#txt1").val());
var txt2 = parseInt($("#txt2").val());
var ans = txt1 + txt2;
alert(ans);
}
</script>
</body>
</html>
var ans = txt1 + txt2;
Here addition, subtraction, multiplication, division can be done. Only for subtraction instead of + - for multiplication * for division / sign.