Showing posts with label Addition and Subtraction of Two Numbers in JavaScript. Show all posts
Showing posts with label Addition and Subtraction of Two Numbers in JavaScript. Show all posts

Saturday, May 14, 2016

Addition and Subtraction of Two Numbers in JavaScript

Hi there thank you for visiting my website I have  a very busy week in my work that why I was not able to update my blog anyway moving forward. In this sample program will show you how to add and subtract two numbers using HTML forms in JavaScript. The code is very easy to understand for beginners that are new in JavaScript. I hope you will find my work useful.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

<!DOCTYPE html>  
<html>   
<head>  
<meta charset=utf-8 />  
<title>Addition and Subtraction of Two Numbers in JavaScript</title>  
<style type="text/css">  
body {
    font-family:arial;
font-size:12;
font-weight:bold;
    background-color:lightgreen;
margin: 30px;
}
</style>   
</head>  
<body>  
<script>
function AdditionBy()  
{  
        num1 = document.getElementById("first").value;  
        num2 = document.getElementById("second").value;  
        document.getElementById("result").innerHTML = Number(num1) + Number(num2);  
}  
  
function SubtractionBy()   
{   
        num1 = document.getElementById("first").value;  
        num2 = document.getElementById("second").value;  
        document.getElementById("result").innerHTML = Number(num1) - Number(num2);  
}  
</script>
<hr>
<h2> Addition and Subtraction of Two Numbers in JavaScript </h2>
 <hr>

<form>  
Give 1st Number : <input type="text" id="first"  maxlength="4"/ size="4"><br>  
Give 2nd Number : <input type="text" id="second"  maxlength="4" size="4" />
<br><br>
<input type="button" onClick="AdditionBy()" Value="Addition" 
title="Click here to find the sum of the two numbers." />  &nbsp;
<input type="button" onClick="SubtractionBy()" 
title="Click here to find the differece of the two numbers." 
Value="Subtraction" />  
</form>  <br><br>
<p>The Final Result is : 
<span id = "result"></span>  
</p>  
</body>  
</html>