I am trying to capture user input from a form by getting the values and then pushing them into an array. I then want to output them with an alert but for some reason the values are getting concatenated instead of added. I also have a random zero with my output. I should be getting the total of the three values (example 1+2+3 should give 6, not 0123. Please advise thanks!
function myFunction() {
var totalArray = [];
totalArray.push(document.getElementById('votes1').value);
totalArray.push(document.getElementById('votes2').value);
totalArray.push(document.getElementById('votes3').value);
var totalAmount = 0;
for (var x = 0; x < totalArray.length; x++) {
totalAmount += totalArray[x];
}
alert(totalAmount);
}
myFunction();
<input id="votes1" value="1"/>
<input id="votes2" value="2"/>
<input id="votes3" value="3"/>