Write a javascript program to make a simple calculator

Answer Posted / rehan

<html>
<head><title>Calculator</title>
<script language="javascript">
var inputstring=" "
function updatestring(value)
{
inputstring += value;
document.calculator.input.value=inputstring;
}
</script>
</head>
<body background=flow-yellow.jpg>
<form name="calculator">
<table border=5 bordercolor=pink bgcolor="#ffffcc"><tr ><td>
<input type="text" name="input" maxlength=15 size=27><br />
<input type="button" value=" clear " onclick="input.value=' ';inputstring=' ' ">
<input type="button" value=" mod " onclick="updatestring('%')">
<input type="button" value=" * " onclick="updatestring('*')"><br />
<input type="button" value=" 7 " onclick="updatestring('7')">
<input type="button" value=" 8 " onclick="updatestring('8')">
<input type="button" value=" 9 " onclick="updatestring('9')">
<input type="button" value=" / " onclick="updatestring('/')"><br />
<input type="button" value=" 4 " onclick="updatestring('4')">
<input type="button" value=" 5 " onclick="updatestring('5')">
<input type="button" value=" 6 " onclick="updatestring('6')">
<input type="button" value=" - " onclick="updatestring('-')"><br />
<input type="button" value=" 1 " onclick="updatestring('1')">
<input type="button" value=" 2 " onclick="updatestring('2')">
<input type="button" value=" 3 " onclick="updatestring('3')">
<input type="button" value=" + " onclick="updatestring('+')"><br />
<input type="button" value=" 0 " onclick="updatestring('0')">
<input type="button" value=" 00 " onclick="updatestring('00')">
<input type="button" value=" . " onclick="updatestring('.')">
<input type="button" value=" = " onclick="input.value=eval(inputstring);">
</td></tr>
</table>
</form>
</body>
</html>

Is This Answer Correct ?    32 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference == and === in javascript?

507


Is array an object javascript?

479


What companies use javascript?

469


What is the requirement of debugging in javascript?

488


coding of java scripts

1486






What is difference between java and javascript?

495


How do I start a javascript project?

468


What are all the types of Pop up boxes available in JavaScript?

577


List some features of javascript.

549


What is webpack used for?

460


How to call a function in every x seconds in javascript?

513


How do you check if a variable is an object

537


What does js stand for?

472


How many types of variables are there in javascript?

423


How to setting a cookie with the contents of a textbox?

527