Javascript calculator?

html-css
javascript

#1

How do I go about writing the functions for the multiplication, division, addition, and subtraction?

Here is what I have so far:

<html>
<head> 
<title></title>
<h1> Calculator</h1>
 <script> 
 

function getnumber(theValue) 
{
var strInput = input.value;
strInput += theValue.toString();
input.value = strInput;
 
} 

</script> 
    
    
    
 </head>
    
<body> 
 <INPUT TYPE="button" id="one" OnClick="getnumber(1)" value="1"/>
<INPUT TYPE="button" id="two"   OnCLick="getnumber(2)" value="2"/>
<INPUT TYPE="button" id="three"  OnClick="getnumber(3)" value="3"/>
<INPUT TYPE="button" id="plus"   OnClick="getOp('+')" value="+"/>
<br>
<INPUT TYPE="button" id="four"  onclick="getnumber(4)" value="4"/>
<INPUT TYPE="button" id="five"  onclick="getnumber(5)" value="5"/>
<INPUT TYPE="button" id="six"   onclick="getnumber(6)" value="6"/>
<INPUT TYPE="button" id="minus"   OnClick="getOp('-')" value="-"/>
<br>
<INPUT TYPE="button" id="seven" OnClick="getnumber(7)" value="7"/>
<INPUT TYPE="button" id="eight"  OnCLick="getnumber(8)" value="8"/>
<INPUT TYPE="button" id="nine"   OnClick="getnumber(9)" value="9"/>
<INPUT TYPE="button" id="multiply" OnClick="getOp('*')" value="*"/>
<br>
<INPUT TYPE="button" id="clear" VALUE="  c  " OnClick="Calc.Input.value = ''">
<INPUT TYPE="button" id="zero"  VALUE="  0  " OnClick="getnumber(0) += '0'">
<INPUT TYPE="button" id="letsgo"  VALUE="  =  " OnClick="Calc.Input.value = eval(Calc.Input.value)">
<INPUT TYPE="button" id="div" OnClick="getOp('/')" value="/">
<INPUT TYPE= "text" id= "input"/>
<br>

    
</body>






</html>

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.