Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Calolatrice</title>
- <script type=text/javascript>
- var SchiacciatoOperatore = true, OperazionePrecedente = "=", Accumulatore = 0;
- function Cifra(Out, Valore) {
- if (SchiacciatoOperatore || Out.value == "0") { Out.value = ""; SchiacciatoOperatore = false; }
- Out.value += Valore
- }
- function Operatore(Out, Valore) {
- switch(OperazionePrecedente) {
- case "/": if (Out.value == "0") alert("divisione per zero!!!");
- else Out.value = Accumulatore / Number(Out.value);
- break;
- case "*": Out.value = Accumulatore * Number(Out.value);
- break;
- case "-": Out.value = Accumulatore - Number(Out.value);
- break;
- case "+": Out.value = Accumulatore + Number(Out.value);
- break;
- case "=": // l'uguale conclude, dunque non fa azioni proprie
- break;
- }
- SchiacciatoOperatore = true; OperazionePrecedente = Valore; Accumulatore = Number(Out.value);
- }
- function CambiaSegno(Out) {
- Out.value = -Number(Out.value)
- }
- </script>
- </head>
- <body>
- <form name=Calc>
- <table align=center>
- <tr>
- <td colspan=4><input type=text name=Display value="0" style="width:100%;text-align:right"></td>
- </tr><tr>
- <td><input type=button value="7" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="8" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="9" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="/" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
- </tr><tr>
- <td><input type=button value="4" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="5" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="6" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="*" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
- </tr><tr>
- <td><input type=button value="1" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="2" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="3" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="-" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
- </tr><tr>
- <td><input type=button value="0" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
- <td><input type=button value="+/-" style="width:20pt;height:20pt" onclick='javascript: CambiaSegno(Calc.Display)'></td>
- <td><input type=button value="=" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
- <td><input type=button value="+" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement