Simple calculator
<html>
<body>
<div align="center">
<h2>SIMPLE CALCULATOR</h2>
<script type="text/javascript">
a = ['1','2','3','+','4','5','6','-','7','8','9','*','C','0','=','/']
z = '<td> <input type="button" value="'
document.write('<form name="cal"><table><tr><td colspan="8"> <input type="text" name="get"></td></tr><tr>');
for (var i = 0; i<16; i++)
{
if(i==12)
{
document.write('<td> <input type="reset" value="C" ></td>');
continue ;
}
if(i==14)
{
document.write('<td> <input type="button" value="=" onclick="cal.get.value =eval(cal.get.value)"></td>');
continue ;
}
if(i==3||i==7||i==11)
{
document.write(z+a[i]+'" onclick="cal.get.value +=\''+a[i]+'\'"></td></tr><tr rowspan="2">');
continue ;
}
else
document.write(z+a[i]+'" onclick="cal.get.value +=\''+a[i]+'\'"></td>');
}
document.write('</table></form></div>');
</script>
</body> </html>
Comments
Post a Comment