The code below is outputting a string of numbers instead of the sum of the numbers in the array. For example, if n is set to 3 and the numbers 1 2 3 are added to the array the output is 0123 when I need it to be 6. I can only use while loops and not for loops for this which is why the code looks slightly odd. Can someone please explain to me why the output is a string and not the sum of the numbers?
var n = -1;
var n2 = 0;
var numbers = [];
while (n < 0) {
n = prompt("Please enter a positive interger");
}
while (n > 0) {
n2 = prompt("Please enter a interger");
numbers.push(n2);
n = n - 1
}
var sum = numbers.reduce(function(a, b){
return a + b;
}, 0);
alert(sum);