Array average of marks

Array average of marks
0.0 0

#1

my task:
‘‘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…


#2

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


#3

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

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

it doesn’t work =(


#4

What’s your fixed code?


#5
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);
    }
}

#6

bad spelling of the word length.


#7

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);
    }

#8

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


#9

thanks!!)) :+1: I’ve understood