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
What would be the result of 3+2+”7″?
How do I open javascript in browser?
What will be the output of the following statements?
What is arguments object in JavaScript?
How to enabled 'Strict' mode in JavaScript?
Why is javascript used for web pages?
Why is javascript hoisting?
Consider the following code: 1 2 3 4 5 (function() { var a = b = 5; })(); console.log(b); what will be printed on the console?
Does javascript support foreach loop?
How many types of functions JavaScript supports?
Can I write javascript in notepad?
What is the requirement of debugging in javascript?
What is the use of a boolean object in javascript?
What is DOM? What is the use of document object?
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.