I haven't added my codewars on here which is annoying me. My time management lately has been very off this entire month of July so far we have all been sick on and off. Just recently my family caught covid so it's been annoying.
I wanted to come in here to document my codewar today because I could not get it right. I looked up the solutions to find where I went wrong and found a similar code. I tried to compare them and I cannot find where I went wrong. Maybe someone here will see it and help me out!
Problem: 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.
function getAverage(marks){
let total = 0;
for(let i = 0; i < marks.legth; i++){
total += marks[i];
}
return Math.floor(total / marks.length);
}
It did not pass saying that the average should be 2 and it's coming out 0.
Now I went to see the solutions to learn from them and I found this:
function getAverage(marks){
// calculates total number of marks
var total = 0;
for(var i = 0; i < marks.length; i++){
total += marks[i];
}
/* returns total number of marks divided by number of marks
rounded down to nearest integer */
return Math.floor(total / marks.length);
}
I cannot see where I went wrong! I thought that maybe writing it out here will help me. Frustration is on but will not beat me!