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 is the scope variable in javascript?
What is the difference of "settimeout" function and setinterval functions in javascript
Which built-in method sorts the elements of an array?
Hello , I am using following java script to open new window in I.E,but i am facing an issue the new window hangs often while opening,when you move mouse it opens normally.Can any body help me why this is happening as i am unable to understand this issue?please please if any one know so kindly help me I am in real difficulty through this issue.Thanks 'if(window.clipboardData){clipboardData.setData("Text","' + a.PatID + '");}' + 'ordwindow= window.open ("' + @OrderDetailURL + '", "RXOrderDetail", "location=0,status=0,menubar=0,toolba r=0,scrollbars=1,resizable=1"); ordwindow.moveTo(parent.screenLeft,0);var x; x=new ActiveXObject("WScript.Shell");x.SendKeys("% "); x.SendKeys ("x"); //fcttest((sp_RX_ChangeOrderStatus ' + '''' + a.DocID + '''' + ', 1, ' + convert(varchar,@SessionID) + '));' As [W],
What is event bubbling in the dom?
Is a hash table an array?
How to modify the url of the page without reloading the page?
Can you use javascript to hack?
How do I run javascript on my iphone?
How to delete a cookie using javascript?
How to change video files randomly after completing its execution in Javascript?
In Java coding we will write a public static void main()? Why won't we write as a static public void main()
How do I install javascript?
What is decodeuri(), encodeuri() in javascript?
How is javascript different from java?