Create JavaScript program to create mathematical calculator.(functionality-+,*,-,/)
CODING:
<html>
<head>
<title>
</title>
<script>
function sum(){
var a,b;
a=Number(document.getElementById("no").value);
b=Number(document.getElementById("mo").value);
document.getElementById("ans").value=a+b;
}
function sub(){
var c,d;
c=Number(document.getElementById("no").value);
d=Number(document.getElementById("mo").value);
document.getElementById("ans").value=c-d;
}
function mult(){
var e,f;
e=Number(document.getElementById("no").value);
f=Number(document.getElementById("mo").value);
document.getElementById("ans").value=e*f;
}
function divd(){
var g,h;
g=Number(document.getElementById("no").value);
h=Number(document.getElementById("mo").value);
document.getElementById("ans").value=g/h;
}
</script>
</head>
<body>
<h3 align="center">NUMBER:<input type="text" id="no" placeholder="Only Numeric Value">
<br><br>NUMBER:<input type="text" id="mo" placeholder="Only Numeric Value"><br><br>
<input type="button" value=" + " onclick="sum()">
<input type="button" value=" - " onclick="sub()">
<input type="button" value=" * " onclick="mult()">
<input type="button" value=" / " onclick="divd()">
<br><br><input type="text" id="ans" placeholder="Click Any Operation." >
</body>
</html>
CODING:
<html>
<head>
<title>
</title>
<script>
function sum(){
var a,b;
a=Number(document.getElementById("no").value);
b=Number(document.getElementById("mo").value);
document.getElementById("ans").value=a+b;
}
function sub(){
var c,d;
c=Number(document.getElementById("no").value);
d=Number(document.getElementById("mo").value);
document.getElementById("ans").value=c-d;
}
function mult(){
var e,f;
e=Number(document.getElementById("no").value);
f=Number(document.getElementById("mo").value);
document.getElementById("ans").value=e*f;
}
function divd(){
var g,h;
g=Number(document.getElementById("no").value);
h=Number(document.getElementById("mo").value);
document.getElementById("ans").value=g/h;
}
</script>
</head>
<body>
<h3 align="center">NUMBER:<input type="text" id="no" placeholder="Only Numeric Value">
<br><br>NUMBER:<input type="text" id="mo" placeholder="Only Numeric Value"><br><br>
<input type="button" value=" + " onclick="sum()">
<input type="button" value=" - " onclick="sub()">
<input type="button" value=" * " onclick="mult()">
<input type="button" value=" / " onclick="divd()">
<br><br><input type="text" id="ans" placeholder="Click Any Operation." >
</body>
</html>
Comments
Post a Comment