Search the Community
Showing results for tags 'sem eval'.
Found 1 result
-
Oi gente ^^ Tenho que fazer uma calculadora em javascript que só faça soma e subtração, sem usar a função eval! Já olhei em 8475853443753450642 fóruns e não encontrei nada que pudesse me ajudar efetivamente. O pessoal pra resolver o problema de ter duas variáveis somando, acaba usando dois <input type="text"> só que eu só posso usar um... realmente não estou conseguindo desenvolver esse código, se alguém puder ajudar POR FAVOR AJUDE hahaha tenho até as 22:00 pra entregar esta bagaça. O que eu tenho por enquanto é isso (com eval): -----------------HTML----------------- <form name="form"> <table> <tr> <input type="text" id="tela"> </tr> <tr> <td><input type="button" value="7" onclick="verConta(value);"></td> <td><input type="button" value="8" onclick="verConta(value);"></td> <td><input type="button" value="9" onclick="verConta(value);"></td> </tr> <tr> <td><input type="button" value="4" onclick="verConta(value);"></td> <td><input type="button" value="5" onclick="verConta(value);"></td> <td><input type="button" value="6" onclick="verConta(value);"></td> </tr> <tr> <td><input type="button" value="1" onclick="verConta(value);"></td> <td><input type="button" value="2" onclick="verConta(value);"></td> <td><input type="button" value="3" onclick="verConta(value);"></td> </tr> <tr> <td><input type="button" value="-" onclick="verConta(value);"></td> <td><input type="button" value="0" onclick="verConta(value);"></td> <td><input type="button" value="+" onclick="verConta(value);"></td> </tr> <tr> <td><input type="button" value="CL" onclick="CL()"></td> <td><input type="button" value="=" onclick="verResultado();"></td> <td><input type="button" value=""></td> </tr> </table> </form> -----------------JAVASCRIPT----------------- function verConta(valor){ document.getElementById('tela').value += valor; } function CL(){ document.getElementById('tela').value =""; } function verResultado(valor){ var total = 0; total = document.getElementById('tela').value; CL(); document.getElementById('tela').value = eval(total); } :(
- 2 replies
-
- html
- javascript
-
(and 3 more)
Tagged with: