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>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<b> enter second number </b>
<form action="">
<input type="text" name="firstnum" id="first">
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<input type="text" name="lastnum" id="second">
</form>

<br> </br>
<button onclick="sum()"> + </button>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<button onclick="sub()"> - </button>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<button onclick="mul()"> * </button>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<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


Please Help Members By Posting Answers For Below Questions

Which javascript is best?

511


List html dom mouse events?

513


how to hide alphabets in java as password '*'

1692


What is callback?

590


Why it is not advised to use innerhtml in javascript?

522






Can I learn javascript without knowing java?

485


What is console.log() and why it is used?

593


How are DOM utilized in JavaScript?

678


What's the Difference Between Class and Prototypal Inheritance?

637


Explain the difference between javascript and an asp script.

506


How do you write an event emitter base class that allows you to add event listeners?

557


Explain javascript event delegation model?

525


Is javascript whitespace sensitive?

491


What is a method in javascript?

509


What is event bubbling and capturing in javascript?

513