Learning JavaScript has been a bit challenging for me, especially when it comes to simple concepts. I'm trying to write code that sums two numbers together, but for some reason, it's not working.
function sum() {
var number1 = document.getElementById('tn1')
var number2 = document.querySelector('input#n2')
var num1 = Number(number1.value)
var num2 = Number(number2.value)
var total = num1 + num2
document.write(total)
}
<body>
<input type="number" id="tn1"> +
<input type="number" id="tn2">
<input type="button" value="Sum" onclick="sum()">
</body>
I know it's probably just a simple mistake, but I can't seem to figure it out.