Write a javascript program to make a simple calculator
Answer Posted / ruchi goswami
<html>
<head>
<link rel="stylesheet" type="text/css" href="css2.css">
<title> calculator </title>
</head>
<body>
<div id="wrap">
<h1> Calculator </h1>
<b> enter first number </b>
                   
<b> enter second number </b>
<form action="">
<input type="text" name="firstnum" id="first">
                   
<input type="text" name="lastnum" id="second">
</form>
<br> </br>
<button onclick="sum()"> + </button>
               
<button onclick="sub()"> - </button>
               
<button onclick="mul()"> * </button>
               
<button onclick="divi()"> / </button>
<br> </br>
<input type="text" id="result">
<p id="demo"></p>
<script>
function sum()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a+b;
document.getElementById("result").value = c;
}
function sub()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a-b;
document.getElementById("result").value = c;
}
function mul()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a*b;
document.getElementById("result").value = c;
}
function divi()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a/b;
document.getElementById("result").value = c;
}
</script>
</div>
</body>
</html>
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Is javascript frontend or backend?
What is the difference between undefined value and null value?
What are the primitive data types in JavaScript?
What is a class in javascript?
what is function of stdio.h
What value does prompt() return if the user clicked the cancel button?
How do you organize your JavaScript code?
What is difference between api and library?
Create an array in javascript with a list of 4 colors, assign that array to the variable, ‘colors’.
What are javascript objects?
How do I open javascript?
Is javascript event driven?
What exactly does javascript do?
What is javascript and its advantages?
What is singleton class in javascript? Explain