I have three inputs which I want to add, When I place my first digit "5" console.log shows "0" the next input field I enter "2" this will console.log the first input field's digit "5" the third I enter "5" I see in console.log "7".
Why is this happening and how do I fix it please.
<input id="roundOne" onkeypress="obtainScoreOne()" type="text">
<input id="roundTwo" onkeypress="obtainScoreOne()" type="text">
<input id="roundThree" onkeypress="obtainScoreOne()" type="text">
JavaScript.
function mathScore(x, y, z){
return (x + y + z);
}
function obtainScoreOne() {
//collect data
let n1, n2, n3, sum;
n1 = Number(document.querySelector('#roundOne').value);
n2 = Number(document.querySelector('#roundTwo').value);
n3 = Number(document.querySelector('#roundThree').value);
sum = mathScore(n1, n2, n3);
//Display result
console.log(sum);
}