Q. How to design a simple working calculator ?
<html>
<head>
<script>
var n1,n2,type
function clk(a)
{
t=a;
for(i=0;i<=9;i++)
{
if(i==t)
{
if(document.hi.t1.value=="")
{
document.hi.t1.value=String(t);
}
else
{
document.hi.t1.value=document.hi.t1.value+String(t);
}
}
}
}
function clik(a)
{
tp=a;
n1=parseInt(document.hi.t1.value);
for(i=0;i<=5;i++)
{
if(i==tp)
{
type=i;
document.hi.t1.value="";
}
}
}
function clp()
{
n2=parseInt(document.hi.t1.value);
switch(type)
{
case 1:n2=n1+n2;document.hi.t1.value=n2;break;
case 2:n2=n1-n2;document.hi.t1.value=n2;break;
case 3:n2=n1*n2;document.hi.t1.value=n2;break;
case 4:n2=n1%n2;document.hi.t1.value=n2;break;
case 5:n2=n1/n2;document.hi.t1.value=n2;break;
}
}
</script>
</head>
<body>
<Form name="hi">
<center><h3><b>CALCULATOR</b></h3><br><br><br>
<table border=1 cellpadding=11>
<form onReset>
<tr>
<th colspan=4><input type=textbox size="25" name=t1>
</tr>
<tr>
<td><b><input type=reset value="C" onClick="Reset"></b></td>
<td><b><input type=button value="1" onClick="clk(1)"></b></td>
<td><b><input type=button value="2" onClick="clk(2)"></b></td>
<td><b><input type=button value="3" onClick="clk(3)"></b></td>
</tr>
<tr>
<td><b><input type=button value="4" onClick="clk(4)"></b></td>
<td><b><input type=button value="5" onClick="clk(5)"></b></td>
<td><b><input type=button value="6" onClick="clk(6)"></b></td>
<td><b><input type=button value="7" onClick="clk(7)"></b></td>
</tr>
<tr>
<td><b><input type=button value="8" onClick="clk(8)"></b></td>
<td><b><input type=button value="9" onClick="clk(9)"></b></td>
<td><b><input type=button value="0" onClick="clk(0)"></b></td>
<td><b><input type=button value="=" onClick="clp()"></b></td>
</tr>
<tr>
<td><b><input type=button value="+" onClick="clik(1)"></b></td>
<td><b><input type=button value="-" onClick="clik(2)"></b></td>
<td><b><input type=button value="*" onClick="clik(3)"></b></td>
<td><b><input type=button value="%" onClick="clik(4)"></b></td>
</td><tr>
<td colspan=2><b><input type=button value="/" onClick="clik(5)"></b></td>
<td colspan=2><b><input type=button value="Exit" onClick="window.close()"></b></td>
</tr>
</table></form>
</body>
</html>