Tell us what’s happening:
Hello I need help with my code below, I don’t know how to do it,
Your code so far
// User Editable Region
function getAverage(scores) {
let sum = 0;
for(let i =0;scores.length;i++ ){
average= sum/scores.length;}
return getAverage;
}
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
console.log(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]));
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1
1 Like
ILM
June 6, 2024, 9:05am
2
you have the loop for what reason? you never use i, and you just do that calculation. Also right now sum is 0, you need to calculate it to have a proper average
1 Like
toan
June 6, 2024, 9:06am
3
Step 1:
Use the for loop to iterate through the scores array and calculate the sum of its items.
Step 2:
Outside of the for loop, calculate the average by using the statement you wrote:
average = sum/scores.length;
Remember to declare average first.
Step 3:
return the average value.
1 Like
function getAverage(scores) {
let scores = 0;
for(let i=0;i<scores.length;i++){
sum+=scores[i];}
}
this is my first step ,
1 Like
ILM
June 6, 2024, 9:43am
5
you have an issue, the function parameter is scores, then you create a variable scores losing access to the function parameter
ashwinikul80:
let scores = 0;
do not use the name scores for this variable
1 Like
Thnx for help i got the code done.
system
Closed
December 6, 2024, 2:10am
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.