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

What would be the result of 3+2+”7″?

741


How do I open javascript in browser?

447


What will be the output of the following statements?

491


What is arguments object in JavaScript?

547


How to enabled 'Strict' mode in JavaScript?

568






Why is javascript used for web pages?

424


Why is javascript hoisting?

443


Consider the following code: 1 2 3 4 5 (function() { var a = b = 5; })(); console.log(b); what will be printed on the console?

462


Does javascript support foreach loop?

504


How many types of functions JavaScript supports?

500


Can I write javascript in notepad?

500


What is the requirement of debugging in javascript?

482


What is the use of a boolean object in javascript?

475


What is DOM? What is the use of document object?

549


A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.38, and the profit of each carton of milk is $0.27. Write a java program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.

1601