Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

If I’m being honest I don’t really know what I’m doing. I think I hard-coded my thing. Can someone help me get the average of all of the numbers?

Your code so far


// User Editable Region

let numbers = [92, 88, 12, 77, 57, 100, 67, 38, 97, 89];
  let sum = 0;
  for (let i = 0; i < numbers.length; i++) {
    sum += numbers[i];
  }

function getAverage(scores) {
  return 71.7;
}
let scores = 717/10;

console.log(scores);
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 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

you need to build the function, this function always return 71.7 indipendently by what series of scores it is given to it.
Try to work only inside the function, from what you wrote I can see you know how to calculate an average

But I’m not sure how to do that.

If it isn’t a problem, would you mind explaining it to me? Thank you.

First ask yourself. What does this function take as input?
How should I use this input to get the average?

Well , if I’m being honest, I’m not sure.

I think that the function takes the multiple scores as an input. And I would add those inputs and divide them by ten to get the average.

if you re-read the instructions you will find the answer there:

Complete the getAverage function which takes in an array of test scores and returns the average score.

so how do you think you should proceed knowing this?

Probably set scores to the arrays and then divide it by ten.

your function getAverage will be given an array so I’m not sure what you mean by “set scores to the arrays”.
You should assume you are getting an array and go from there.

the array and inputs you will get will be passed as argument of the function . You don’t need to hardcode this . first understand the problem :

  1. there is an array passing by user as an argument whose name is scores . only we have to perform our operations over scores array we don’t know what value is getting inside this array for testing.

2.You have to write your logic inside a function whose name is getAverage .you have access of scores array inside this since it is passing as parameter and4. you have to perform your operations inside this function.

  1. Total no. of scores = total no. of input inside scores = scores.length ;
    you have to return a variable name average whose value is :
    sum of all inputs of array / total no. of scores .

hope its all clear for you :blush:

Man, this is confusing.

it’s okay to be confused. Try to tell us what is the confusing part though so we can try to help.

Well, I’ve got steps 1 and 2 down, but steps three and four confuse me. It’s saying that the getAverage function is already used and i’m not sure here to go from here.

Please open a new topic for a different step.

I would tend to agree, use the help button on the step you are on now.

Otherwise, you have to post your new code. This thread was about step 1, but it sounds like you are now on step 3 or 4.


Instruction for posting code:

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').