hercioneto

PW1 2018 calculadora.html

Sep 27th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.31 KB | None | 0 0
  1. <!-- calculadora.html -->
  2. <html>
  3. <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.     <title>Calculadora</title>
  6.  
  7.      <script>
  8. function calcular() {
  9.     var valor1 = document.getElementById("valor1").value;
  10.     var valor2 = document.getElementById("valor2").value;
  11.     var opt = document.getElementById("operacao").value;
  12.     var opt2 = document.getElementById("operacao2").value;
  13.     var resultado = 0;
  14.     if (opt=="+")  resultado = parseInt(valor1) + parseInt(valor2);
  15.     if (opt=="-")  resultado = parseInt(valor1) - parseInt(valor2);
  16.     if (opt=="*")  resultado = parseInt(valor1) * parseInt(valor2);
  17.     if (opt=="/")  resultado = parseInt(valor1) / parseInt(valor2);
  18.     alert(resultado);
  19.     var resu = document.getElementById("resultado");
  20.     resu.innerHTML= resultado;
  21. }
  22. </script>
  23. </head>
  24. <body >
  25. Valor 1: <input type="text" name="valor1" id="valor1"><br/>
  26. Valor 2: <input type="text" name="valor2" id="valor2"><br/>
  27. Operação (+ - * /): <input type="text" name="operacao" id="operacao"><br/>
  28. Operação <select id="operacao2">
  29.     <option value="+">+</option>
  30.     <option value="-">-</option>
  31.     <option value="*">*</option>
  32.     <option value="/">/</option>
  33.  </select>
  34. <br/>
  35. <button onclick="calcular()">Calcular</button><p>
  36. <b><span id="resultado"></span></b></p>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment