<html>
<body>
<script>
function sum() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = +y + +z;
document.getElementById("demo").innerHTML = x;
}
function sub() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = +y - +z;
document.getElementById("demo").innerHTML = x;
}
function div() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = +y / +z;
document.getElementById("demo").innerHTML = x;
}
function mul() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = +y * +z;
document.getElementById("demo").innerHTML = x;
}
</script>
<br/>Enter first number:
<input type="text" id="txt1" name="text1">Enter second number:
<input type="text" id="txt2" name="text2">
<br />
<br />
<button onclick="sum()">SUM</button>
<button onclick="sub()">SUB</button>
<button onclick="mul()">MUL</button>
<button onclick="div()">DIV</button>
<br/>
<p id="demo"></p>
</body>
</html>
Friday, 21 August 2015
Create Calculator using Java Script
Labels:
Java Script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment