calculadora simple
Publicado por L (1 intervención) el 14/06/2021 02:21:50
buenas tardes soy nuevo en javascript y tengo un problema muy basico
tengo un formulario simple en el cual tengo la funcion sumar la cual se llama a traves de un boton en html haciendo un click
esta es la funcion
aqui el html
alguien me podria ayudar porfavor
tengo un formulario simple en el cual tengo la funcion sumar la cual se llama a traves de un boton en html haciendo un click
esta es la funcion
1
2
3
4
5
6
7
8
9
function sumar(){
var n1 = parseInt(document.getElementById('valor1').Value); //aqui no me interpreta el valor como numero
var n2 = parseInt(document.getElementById('valor2').Value);
var suma;
suma = n1 + n2;
document.getElementById("resultado").innerHTML = n1 + n2;//da como resultado NaN
}
aqui el html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<div>
<div>
<h2>
Resultado: <span class="resultado" id="resultado"></span>
</h2>
<div>
<div>
<div>
<label for="">Valor 1</label>
<input id="valor1" type="text">
<button onclick="limpiar()">limpiar campos</button>
</div>
<div>
<label for="">Valor 2</label>
<input id="valor2" type="text">
</div>
<div style="display: flex">
<button id="btn-sumar" type="button" onclick="sumar();">
Sumar
</button>
<button id="btn-restar" onclick="restar();" type="button">
Restar
</button>
</div>
</div>
</div>
</div>
</div>
alguien me podria ayudar porfavor
Valora esta pregunta


0