My code refusing to run help guys

** Your code should return the correct output after modifying the watchList object:**

Your code so far

function getRating(watchList){

  // Only change code below this line

  var averageRating;

  watchList

    // Use filter to find films directed by Christopher Nolan

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

    // Use map to convert their ratings from strings to numbers

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

    // Use reduce to add together their ratings

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

  // Divide by the number of Nolan films to get the average rating

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

  // Add your code above this line

  return averageRating;

}

console.log(getRating(watchList));

Your browser information:

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

Challenge: Use the reduce Method to Analyze Data

Link to the challenge:

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

Are these two lines doing what you think they are doing?

no they are not doing what I want

Let me rephrase. What do you think the two lines I quoted are doing?

var averageRating its representing the rating of IMBD w
watchlist is calling watch list above

But you never assign anything into the variable averageRating

didn’t notice can you explain how I can debbug my error please

To fix this, you just need to replace the ; with a different symbol to save the result on the next line into the averageRating variable.

As to how I debugged this - the failing test said the output was wrong. You are returning the averageRating variable, so I looked at your code to see what was being stored in that variable.

now the problem is the .filter

do you mind if we can keep on chatting on skype … actuallly I am still a beginner

I don’t really do chat… plus I’m at work…

When I swap the ; for a =, your code seems to work fine for me.

I really need a person who knows oding to help when I need help not just chatting

You won’t get help much faster than you get here on the forum unless you pay the hourly rate of a professional developer… which is not going to be cheep.

Personally, I just stick to giving away my knowledege for free on the forum.

I am patient enough to wait for the help…it won’t be like when I need I will get

I suggest you post the last code you have and explain what issue you have now, so that people knows where you are and can help you with that

2 Likes

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