diff --git a/calculadora.html b/calculadora.html index bc24304..70f8642 100644 --- a/calculadora.html +++ b/calculadora.html @@ -3,14 +3,14 @@ - Page Title + Calculadora

- + diff --git a/main.css b/main.css new file mode 100644 index 0000000..62ab84c --- /dev/null +++ b/main.css @@ -0,0 +1,19 @@ +#screen-anterior,#screen{ + width: 11em; + height: 2em; + margin-left: 30%; + text-align: right; +} + +.tecla{ + border: 2px solid; + padding: 3px; + height: 2em; + width: 2em; + padding:0px; + text-align: center; +} + +table{ + margin-left: 30%; +} \ No newline at end of file diff --git a/main.js b/main.js index 146ee77..8af236b 100644 --- a/main.js +++ b/main.js @@ -1,14 +1,14 @@ const teclas = document.querySelectorAll('.tecla'); var screen = document.getElementById("screen"); var screenAnterior = document.getElementById("screen-anterior"); -var entrada_anterior; +var entrada_anterior=""; var dot_posible = true; -var escribir = function(event) { - let contenido = event.target.innerHTML; + +var escribir = function(contenido) { switch (getTipo(contenido)) { case "num": switch (getTipo(entrada_anterior)) { - case "num": + case "num": case "": screen.value = Number(screen.value + contenido) break; case "op": @@ -102,6 +102,7 @@ function getTipo(valor){ if(esOperador(valor)) return "op"; if(valor=="=") return "eq"; if(valor==".") return "dot"; + return valor; } function operar(a,b,op){ @@ -121,4 +122,5 @@ function operar(a,b,op){ } } -teclas.forEach(el => el.addEventListener('click', escribir)); \ No newline at end of file +teclas.forEach(el => el.addEventListener('click', event =>{escribir(event.target.innerHTML)})); +document.addEventListener('keypress',event => {escribir(event.key)}) \ No newline at end of file
7 8 9 +