Christopher Nolan average rating

Tell us what’s happening:

i cant pass the test

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.


Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36.

Challenge: Use the reduce Method to Analyze Data

Link to the challenge:

Can you please provide your code?

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data

We need to see your code, not a link to the challenge you are working on.


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 (’).

function getRating(watchList){

  var averageRating = watchList

  .filter(film => film.Director === "Christopher Nolan")

  .map(film => Number(film.imdbRating))

  .reduce((sumOfRatings, rating) => sumOfRatings + rating)

  watchList.filter(film => film.Director === "Christopher Nolan").length;

  

  return averageRating;

}

console.log(getRating(watchList));

I’ve edited your post for readability. 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 (’).

I believe that you may be missing a division operation in there.

thanks for informing me about the backticks. please show me how to do the divisional operation

I’m not sure if you fully understood the code you wrote. Can you describe, in words, what your code is doing? If you can describe your code, line by line, in words, then you will be able to see where you need to divide two quantities.

what is this doing on a line on its own?

1 Like

Thank you all I got it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.