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 the instanceof operator in JavaScript?

698


How to convert json object to string?

736


How many functions are there in javascript?

649


Taking a developer's perspective, do you think that that javascript is easy to learn and use?

682


What is the prototype object in javascript and how it is used?

720


What are Cookies in Javascript?

756


How to convert a string to a number using javascript?

681


What do you mean by enumeration?

664


Who introduced javascript?

681


How do I turn on javascript on my phone?

618


How to show progress bar while loading using ajax call?

740


In Java coding we will write a public static void main()? Why won't we write as a static public void main()

2298


How to manage exception handling in javascript?

711


how do you declare variables in javascript?

675


If an array with name as "names" contain three elements, then how will you print the third element of this array?

718