-1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>somando valores</title>
<style>
*{
font: normal 20pt arial;
}
div{
width: 300px ;
height: 100px;
margin-top: 50px;
background: rgb(47, 47, 255);
color: white;
text-align: center;
line-height: 90px;
}
</style>
</head>
<body>
<h1>somando valores</h1>
<input type="number" name="txtn1" id="txtn1" >
<input type="number" name="txtn2" id="txtn2" >
<div id="somar"> somar </div>
<p id="resultado">?</p>
<script>
var n1 = Number(document.getElementById('txtn1').innerHTML);
var n2 = Number(document.getElementById('txtn2').innerHTML);
var soma = document.getElementById('somar');
soma.addEventListener('click', operacaoSoma);
function operacaoSoma(){
document.getElementById('resultado').innerHTML = n1+n2;
}
</script>
</body>
</html>
Related: https://answall.com/questions/134453/como-converter-uma-string-para-int-em-javascript
– Wallace Maxters