Vous êtes sur la page 1sur 2

ASSIGNEMNT SOLUTION:

CALCULATOR CODING:
<!-- experiments with table & button-input vegaseat 2/13/02 -->
<!-- table, border, cellpadding, cellspacing, input, onClick -->
<!-- uses eval() to do the final calculation -->
<!-- note: eval() traps divide by zero error -->
<html>
<head>
<title>Calculator </title>
</head>
<body>
<form name="calculator">
<table border="4" cellpadding="1" bordercolor="#FFFFFF" bgcolor="#73B27B" cellsp
acing="2" width="376">
<tr>
<td>
<input type="text" size="25" length="25" value="" name="ans" style="background:b
lack;color:white;">
</td>
</tr>
</table>
<table border="4" cellpadding="2" bordercolor="#FFFFFF" cellspacing="2" width="1
50" bgcolor="#73B27B">
<tr>
<td align="center">
<input type="button" value=" 7 " name="seven" onClick="document.calculator.ans.v
alue+='7'">
</td>
<td align="center">
<input type="button" value=" 8 " name="eight" onClick="document.calculator.ans.v
alue+='8'">
</td>
<td align="center">
<input type="button" value=" 9 " name="nine" onClick="document.calculator.ans.va
lue+='9'">
</td>
<td align="center">
<input type="button" value=" DIVISION" name="divide" onClick="document.calculato
r.ans.value+='/'">
</td>
</tr>
<tr>
<td align="center">
<input type="button" value=" 4 " name="four" onClick="document.calculator.ans.va
lue+='4'">
</td>
<td align="center">
<input type="button" value=" 5 " name="five" onClick="document.calculator.ans.va
lue+='5'">
</td>
<td align="center">
<input type="button" value=" 6 " name="six" onClick="document.calculator.ans.val
ue+='6'">
</td>
<td align="center">
<input type="button" value=" MULTIPLICATION" name="multiply" onClick="document.c
alculator.ans.value+='*'">
</td>
</tr>
<tr>
<td align="center">
<input type="button" value=" 1 " name="one" onClick="document.calculator.ans.val
ue+='1'">
</td>
<td align="center">
<input type="button" value=" 2 " name="two" onClick="document.calculator.ans.val
ue+='2'">
</td>
<td align="center">
<input type="button" value=" 3 " name="three" onClick="document.calculator.ans.v
alue+='3'">
</td>
<td align="center">
<input type="button" value=" SUBTRACTION" name="subtract" onClick="document.calc
ulator.ans.value+='-'">
</td>
</tr>
<tr>
<td align="center">
<input type="button" value=" CLEAR" name="clear" onClick="document.calculator.an
s.value=''">
</td>
<td align="center">
<input type="button" value=" 0 " name="zero" onClick="document.calculator.ans.va
lue+='0'">
</td>
<td align="center">
<input type="button" value=" RESULT " name="equal"
onClick="document.calculator.ans.value=eval(document.calculator.ans.value)">
</td>
<td align="center">
<input type="button" value=" ADDITION" name="add" onClick="document.calculator.a
ns.value+='+'">
</td>
</tr>
</table>
</form>
</body>
</html>

Vous aimerez peut-être aussi