I'm trying to make a calculator in javascript. The buttons are already working, but I don't know how to separate the first input from the second input. We're not allowed to use global variables so I can't use the "flag" thing. please help, here's my code so far. thanks!
<html>
<head>
<title>JAVASCRIPT
</title>
<script type = "text/javascript">
function getValue(value){
var x = value;
switch(value){
case '+':
clearScreen();
break;
case '-' :
break;
case '/':
break;
case '*':
break;
case '+/-':
break;
case 'sqrt#':
break;
case '.':
break;
case 'C':
break;
case '=':
break;
default:
document.calc.screen.value +=x;
break;
}
}
function clearScreen(button){
document.calc.screen.value ="";
}
</script>
</head>
<body>
<form name ="calc">
<input type ="text" name ="screen" id="screen" value="1"/>
<br/>
<input type ="button" name ="seven" id="sev" value="7" onClick="getValue(7)"/>
<input type ="button" name ="eight" id="eig" value="8" onClick="getValue(8)"/>
<input type ="button" name ="nine" id="nin" value="9" onClick="getValue(9)"/>
<input type ="button" name ="division" id="div" value="/" onClick="getValue(/)"/>
<input type ="button" name ="claer" id="clr" value="C" onClick="clearScreen(this)"/>
<br/>
<input type ="button" name ="four" id="for" value="4" onClick="getValue(4)"/>
<input type ="button" name ="five" id="fiv" value="5" onClick="getValue(5)"/>
<input type ="button" name ="six" id="sx" value="6" onClick="getValue(6)"/>
<input type ="button" name ="multiplication" id="multi" value="*" onClick="getValue('*')"/>
<input type ="button" name ="squareroot" id="sqrt" value="sqrt#" onClick="getValue('sqrt#')"/>
<br/>
<input type ="button" name ="one" id="on" value="1" onClick="getValue(1)"/>
<input type ="button" name ="two" id="tw" value="2" onClick="getValue(2)"/>
<input type ="button" name ="three" id="tri" value="3" onClick="getValue(3)"/>
<input type ="button" name ="subtraction" id="subtract" value="-" onClick="getValue(-)"/>
<input type ="button" name ="addition" id="add" value="+" onClick="getValue('+')"/>
<br/>
<input type ="button" name ="posneg" id="posneg" value="+/-" onClick="getValue(+/-)"/>
<input type ="button" name ="zero" id="zer" value="0" onClick="getValue(0)"/>
<input type ="button" name ="period" id="dot" value="." onClick="getValue(.)"/>
<input type ="button" name ="equal" id="eql" value="=" onClick="getValue(=)"/>
</form>
</body>
</html>