Arrays properties and methods practice
Can any one please tell me why this one doesn't work: function main() { //take the number of passed levels var levels = parseInt(readLine(),10); var points = new Array(); var count = 0; while(count<levels){ var elem = parseInt(readLine(),10); points[count] = elem; count++; } var sum = 0; //calculate the sum of points while(count!=0) { sum += points[count]; count-- } //output console.log(sum); } but this one does? function main() { //take the number of passed levels var levels = parseInt(readLine(),10); var points = new Array(); var count = 0; while(count<levels){ var elem = parseInt(readLine(),10); points[count] = elem; count++; } var sum = 0; //calculate the sum of points a = 0; while(a<points.length) { sum += points[a]; a++ } //output console.log(sum); }