Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- calculadora.html -->
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Calculadora</title>
- <script>
- function calcular() {
- var valor1 = document.getElementById("valor1").value;
- var valor2 = document.getElementById("valor2").value;
- var opt = document.getElementById("operacao").value;
- var opt2 = document.getElementById("operacao2").value;
- var resultado = 0;
- if (opt=="+") resultado = parseInt(valor1) + parseInt(valor2);
- if (opt=="-") resultado = parseInt(valor1) - parseInt(valor2);
- if (opt=="*") resultado = parseInt(valor1) * parseInt(valor2);
- if (opt=="/") resultado = parseInt(valor1) / parseInt(valor2);
- alert(resultado);
- var resu = document.getElementById("resultado");
- resu.innerHTML= resultado;
- }
- </script>
- </head>
- <body >
- Valor 1: <input type="text" name="valor1" id="valor1"><br/>
- Valor 2: <input type="text" name="valor2" id="valor2"><br/>
- Operação (+ - * /): <input type="text" name="operacao" id="operacao"><br/>
- Operação <select id="operacao2">
- <option value="+">+</option>
- <option value="-">-</option>
- <option value="*">*</option>
- <option value="/">/</option>
- </select>
- <br/>
- <button onclick="calcular()">Calcular</button><p>
- <b><span id="resultado"></span></b></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment