I have tried to make a while loop where I add all the numbers of the array to one sum. I keep on getting an endless loop. I’ve also tried to do (array.length) (array.length –) (array.length>numbers)
But nothing I tried worked… any suggestions? 🙂
function sumNumbersWhileLoop(array, sum) {
array = [1, 5, 4, 6, 7];
sum = 0;
for (let numbers of array) {
while (array.length>0) {
sum += numbers;
console.log(sum);
}
}
}