I am currently working on a JavaScript program that involves updating numbers in a field based on user input. For example, if the initial number in the field is 5 and the user enters 4 in the textfield, then the field should display the total of both numbers which would be 9.
document.getElementById('btn').addEventListener('click', () => {
console.log("Button clicked")
var newTotal = 0
var input = parseInt(document.getElementById('text').value)
newTotal = input
if (newTotal) {
console.log(newTotal)
newTotal += input
}
console.log(newTotal)
document.getElementById('textField').innerHTML = newTotal
document.getElementById('text').value = ''
})
<input type="text" id="text">
<h3><span id="textField">0</span></h3>
<input type="submit" id="btn" value="Add Numbers">