Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.66 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title>Calolatrice</title>
  4.     <script type=text/javascript>
  5.       var SchiacciatoOperatore = true, OperazionePrecedente = "=", Accumulatore = 0;
  6.       function Cifra(Out, Valore) {
  7.         if (SchiacciatoOperatore || Out.value == "0")  { Out.value = ""; SchiacciatoOperatore = false; }
  8.         Out.value += Valore
  9.       }
  10.       function Operatore(Out, Valore) {
  11.        
  12.         switch(OperazionePrecedente) {
  13.           case "/":  if (Out.value == "0")  alert("divisione per zero!!!");
  14.                      else Out.value = Accumulatore / Number(Out.value);
  15.                      break;
  16.           case "*":  Out.value = Accumulatore * Number(Out.value);
  17.                      break;
  18.           case "-":  Out.value = Accumulatore - Number(Out.value);
  19.                      break;
  20.           case "+":  Out.value = Accumulatore + Number(Out.value);
  21.                      break;
  22.           case "=":  // l'uguale conclude, dunque non fa azioni proprie
  23.                      break;
  24.         }
  25.         SchiacciatoOperatore = true; OperazionePrecedente = Valore;  Accumulatore = Number(Out.value);
  26.       }
  27.       function CambiaSegno(Out) {
  28.         Out.value = -Number(Out.value)
  29.       }
  30.      </script>
  31.   </head>
  32.   <body>
  33.     <form name=Calc>
  34.       <table align=center>
  35.         <tr>
  36.           <td colspan=4><input type=text name=Display value="0" style="width:100%;text-align:right"></td>
  37.         </tr><tr>
  38.           <td><input type=button value="7" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  39.           <td><input type=button value="8" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  40.           <td><input type=button value="9" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  41.           <td><input type=button value="/" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
  42.         </tr><tr>
  43.           <td><input type=button value="4" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  44.           <td><input type=button value="5" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  45.           <td><input type=button value="6" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  46.           <td><input type=button value="*" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
  47.         </tr><tr>
  48.           <td><input type=button value="1" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  49.           <td><input type=button value="2" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  50.           <td><input type=button value="3" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  51.           <td><input type=button value="-" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
  52.         </tr><tr>
  53.           <td><input type=button value="0" style="width:20pt;height:20pt" onclick='javascript: Cifra(Calc.Display, this.value)'></td>
  54.           <td><input type=button value="+/-" style="width:20pt;height:20pt" onclick='javascript: CambiaSegno(Calc.Display)'></td>
  55.           <td><input type=button value="=" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
  56.           <td><input type=button value="+" style="width:20pt;height:20pt" onclick='javascript: Operatore(Calc.Display, this.value)'></td>
  57.         </tr>
  58.       </table>
  59.     </form>
  60.   </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement