# Array average of marks

‘‘It’s the academic year’s end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script.
Return the average of the given array rounded down to its nearest integer.
The array will never be empty.’’

my code:

``````function getAverage(marks){
//TODO : calculate the downwar rounded average of the marks array

var sumMarks = 0;
for (var i=0; i==marks.lenghth-1; i++){
sumMarks+=marks[i];
}

var average = sumMarks / marks.length;

return Math.floor(average);
}
``````

help or bettetr give me some correct tips…

Your loop never runs except for when `marks.length === 1`, check your condition in `for` loop.

i corrected it and loop began to work, but
for example

``````getAverage([2,2,2,2]);
``````

it doesn’t work =(

``````function getAverage(marks){
//TODO : calculate the downwar rounded average of the marks array

var sumMarks = 0;
for (var i=0; i===marks.lenghth-1; i++){
sumMarks+=marks[i];
}

var average = sumMarks / marks.length;

return Math.floor(average);
}
}
``````

bad spelling of the word length.

The average of 1,2,15,15,17,11,12,17,17,14,13,15,6,11,8,7 should return - Expected: 11, instead got: 0

``````function getAverage(marks){
//TODO : calculate the downwar rounded average of the marks array

var sumMarks = 0;
for (var i=0; i===marks.length-1; i++){
sumMarks+=marks[i];
}

var average = sumMarks / marks.length;

return Math.floor(average);
}
``````

You didn’t fix anything. Your loop condition is the same as before.

1 Like

thanks!!)) I’ve understood