-2
I am studying Javascript, and during this example I came across an error that I could not solve.
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Somando Números</title>
</head>
<body>
<h1>Somando Valores</h1>
<input type="number" name="txtn1" id="txtn1"> +
<input type="number" name="txtn2" id="txtn2">
<input type="button" value="Somar" onclick="somar()">
<div id="res">Resultado</div>
<script>
function somar() {
let tn1 = window.document.getElementById('txtn1')
let tn2 = window.document.getElementById('txtn2')
let res = window.document.getElementById('res')
let n1 = Number(tn1.value)
let n2 = Number(tn2.value)
let s = n1 + n2
res.innerHTML = `A soma entre ${tn1} e ${tn2} é ${res}`
}
</script>
</body>
</html>
When adding up the numbers, the result that comes to me is this:
" The sum between [Object Htmlinputelement] and [Object Htmlinputelement] is [Object Htmldivelement]
Was what you wanted to do not
res.innerHTML = \
The sum between ${n1} and ${N2} is ${s}`` ?– Andre