Need guidance with (Use the reduce Method to Analyze Data)

its failing the last test even though am getting the right answer (8.675) can someone tell me what am doing wrong

function getRating(watchList) {
  // Only change code below this line
    let averageRating = watchList
    .filter(x => x.imdbRating > 7.9)
    .reduce((pre, cur) => pre + parseFloat(cur.imdbRating), 0) / 4;
  // Only change code above this line
  return averageRating; // 8.675 which is the right answer


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Use the reduce Method to Analyze Data

Link to the challenge:

Where is this magic number coming from?

so i can get the Average

But it’s just a random 4. Why 4? You are hard cording which means that your function will break with any changes to the input.

Also, is this the requirement in the challenge? I thought it was for movies directed by Christopher Nolan?

1 Like

which means am going in the wrong direction right?

You have some correct parts, you just need to make some fixes

  1. You need to filter movies for the director

  2. You need to compute the 4 instead of hardcoding the ‘magic number’

1 Like

ok perfect thank you :pray: :pray: :pray: :pray:

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