|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html lang="en"> |
| 3 | + |
3 | 4 | <head> |
4 | | - <meta charset="UTF-8"> |
5 | | - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
6 | | - <title>Simple Calculator</title> |
7 | | - <link rel="stylesheet" href="style.css"> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <title>Simple Calculator</title> |
| 8 | + <link rel="stylesheet" href="style.css"> |
| 9 | + <script> |
| 10 | + function assignValue(val) { |
| 11 | + if (calculator.display.value == Infinity) { |
| 12 | + calculator.display.value = val; |
| 13 | + } else { |
| 14 | + calculator.display.value += val; |
| 15 | + } |
| 16 | + } |
| 17 | + </script> |
8 | 18 | </head> |
| 19 | + |
9 | 20 | <body> |
10 | | - <form class="calc" name="calculator"> |
11 | | - <table> |
12 | | - <tr> |
13 | | - <td colspan="5"> |
14 | | - <input type="text" name="display" id="display" disabled> |
15 | | - |
16 | | - </td> |
17 | | - </tr> |
18 | | - <tr> |
19 | | - <td><input type="button" name="one" value="1" onclick="calculator.display.value += '1'"></td> |
20 | | - <td><input type="button" name="two" value="2" onclick="calculator.display.value += '2'"></td> |
21 | | - <td><input type="button" name="three" value="3" onclick="calculator.display.value += '3'"></td> |
22 | | - <td><input type="button" class="operator" name="plus" value="+" onclick="calculator.display.value += '+'"></td> |
23 | | - <td><input type="button" class="operator" name="power" value="**" onclick="calculator.display.value += '**'"></td> |
24 | | - </tr> |
25 | | - <tr> |
26 | | - <td><input type="button" name="four" value="4" onclick="calculator.display.value += '4'"></td> |
27 | | - <td><input type="button" name="five" value="5" onclick="calculator.display.value += '5'"></td> |
28 | | - <td><input type="button" name="six" value="6" onclick="calculator.display.value += '6'"></td> |
29 | | - <td><input type="button" class="operator" name="minus" value="-" onclick="calculator.display.value += '-'"></td> |
30 | | - <td><input type="button" name="power2" value="^2" onclick="calculator.display.value += '**2'"></td> |
31 | | - </tr> |
32 | | - <tr> |
33 | | - <td><input type="button" name="seven" value="7" onclick="calculator.display.value += '7'"></td> |
34 | | - <td><input type="button" name="eight" value="8" onclick="calculator.display.value += '8'"></td> |
35 | | - <td><input type="button" name="nine" value="9" onclick="calculator.display.value += '9'"></td> |
36 | | - <td><input type="button" class="operator" name="times" value="x" onclick="calculator.display.value += '*'"></td> |
37 | | - <td><input type="button" class="operator" name="div" value="/" onclick="calculator.display.value += '/'"></td> |
38 | | - </tr> |
39 | | - <tr> |
40 | | - <td><input type="button" id="clear" name="clear" value="c" onclick="calculator.display.value = ''"></td> |
41 | | - <td><input type="button" name="zero" value="0" onclick="calculator.display.value += '0'"></td> |
42 | | - <td><input type="button" name="zero" value="." onclick="calculator.display.value += '.'"></td> |
43 | | - <td><input type="button" name="doit" value="=" onclick="calculator.display.value = eval(calculator.display.value)"></td> |
44 | | - <td><input type="button" name="zero" value="%" onclick="calculator.display.value += '/100*'"></td> |
45 | | - </tr> |
46 | | - </table> |
47 | | - </form> |
| 21 | + <form class="calc" name="calculator"> |
| 22 | + <table> |
| 23 | + <tr> |
| 24 | + <td colspan="5"> |
| 25 | + <input type="text" name="display" id="display" disabled> |
| 26 | + |
| 27 | + </td> |
| 28 | + </tr> |
| 29 | + <tr> |
| 30 | + <td><input type="button" name="one" value="1" onclick="assignValue('1')"></td> |
| 31 | + <td><input type="button" name="two" value="2" onclick="assignValue('2')"></td> |
| 32 | + <td><input type="button" name="three" value="3" onclick="assignValue('3')"></td> |
| 33 | + <td><input type="button" class="operator" name="plus" value="+" onclick="calculator.display.value += '+'"></td> |
| 34 | + <td><input type="button" class="operator" name="power" value="**" onclick="calculator.display.value += '**'"></td> |
| 35 | + </tr> |
| 36 | + <tr> |
| 37 | + <td><input type="button" name="four" value="4" onclick="assignValue('4')"></td> |
| 38 | + <td><input type="button" name="five" value="5" onclick="assignValue('5')"></td> |
| 39 | + <td><input type="button" name="six" value="6" onclick="assignValue('6')"></td> |
| 40 | + <td><input type="button" class="operator" name="minus" value="-" onclick="calculator.display.value += '-'"></td> |
| 41 | + <td><input type="button" name="power2" value="^2" onclick="calculator.display.value += '**2'"></td> |
| 42 | + </tr> |
| 43 | + <tr> |
| 44 | + <td><input type="button" name="seven" value="7" onclick="assignValue('7')"></td> |
| 45 | + <td><input type="button" name="eight" value="8" onclick="assignValue('8')"></td> |
| 46 | + <td><input type="button" name="nine" value="9" onclick="assignValue('9')"></td> |
| 47 | + <td><input type="button" class="operator" name="times" value="x" onclick="calculator.display.value += '*'"></td> |
| 48 | + <td><input type="button" class="operator" name="div" value="/" onclick="calculator.display.value += '/'"></td> |
| 49 | + </tr> |
| 50 | + <tr> |
| 51 | + <td><input type="button" id="clear" name="clear" value="c" onclick="calculator.display.value = ''"></td> |
| 52 | + <td><input type="button" name="zero" value="0" onclick="assignValue('0')"></td> |
| 53 | + <td><input type="button" name="zero" value="." onclick="assignValue('.')"></td> |
| 54 | + <td><input type="button" name="doit" value="="onclick="calculator.display.value = eval(calculator.display.value)"></td> |
| 55 | + <td><input type="button" name="zero" value="%" onclick="calculator.display.value = eval(calculator.display.value /100)"></td> |
| 56 | + </tr> |
| 57 | + </table> |
| 58 | + </form> |
48 | 59 | </body> |
| 60 | + |
49 | 61 | </html> |
0 commit comments