So I have written this code to calculate the average marks of students using Javascript. But for some reason it just gives the output as 242628302.6 always. I dont understand whats wrong with the code....Any help would be appreciated.
const marks = [];
var size = 5; //Maximum Array size
for (var i = 0; i < size; i++) { //Taking Input from user
marks[i] = prompt('Enter Element ' + (i + 1));
}
const average = marks => marks.reduce((prev, curr) => prev + curr, 0) / marks.length;
const result = average(marks);
console.log(result);