Addition of Numbers

Hi friends lets see how to do addition of Numbers in a HTML page using JavaScript

Program :

<html>
<body>
<h2> ADDITION </h2>
The Sum of 111 and 112 is
<script>
document.write(111+112);
</script>
</body>
</html>

Program :

<html>
<body>
<h2> ADDITION </h2>
The Sum of x=112 and y=122 is
<script>
var x,y,z;
x=112;
y=122;
z=x+y;
document.write(z);
</script>
</body>
</html>

Program :

<html>
<body>
<h2> ADDITION </h2>
<button type="button" onclick="inputx()">Enter X</button>
<br></br>
<button type="button" onclick="inputy()">Enter Y</button>
<br></br>
<button type="button" onclick="add()">ADD</button>
<script>
var x,y,z;
function inputx()
{
x=prompt("Enter the Value For X");
}
function inputy()
{
y=prompt("Enter the Value for Y");
}
function add()
{
var num1=parseInt(x);
var num2=parseInt(y);
z=num1+num2;
document.write(z);
}
</script>
</body>
</html>



Here you go friends .. The First Code is Just Addition of Numbers and Second one is done by using Variables and in the third one those variables are inputted Dynamically ..
Post your Comments ...


Key~ttu


and you can run the Codes at ..





Comments