I started learning programming a little while ago, but I got stuck on the functions and intervals part.
What I wanted was a very simple system, to do multiplication, using HTML and JavaScript, passing the input numbers as parameters.
However, when I run the code, it returns NaN as the result.
let button = document.querySelector("#button");
let num1 = parseInt(document.getElementById('num1').value);
let num2 = parseInt(document.getElementById('num2').value);
function operacao(a, b) {
let resp = a * b;
return resp;
}
let resto = operacao(num1, num2)
button.addEventListener("click", function() {
document.getElementById('resto').innerHTML = 'O resultado é: ' + resto
});
<label>
Informe os numeros:
<br>
<input type="number" id="num1">
<p>x</p>
<input type="number" id="num2">
</label>
<br>
<br>
<button id="button" onclick=(operacao)>Multiplicar</button>
<p id="resto"></p>