Hello! This is my first time asking for help, as well as my first time on this forum. I have pasted the snippet from the section that this challenge wants one to change, but could anyone help me understand why this doesn’t work? It returns a movie with a rating of less than 8, and I am thoroughly confused… Much thanks for any help as it is greatly appreciated!
// Only change code below this line
var filteredList = watchList.map(movie => ({
"title": movie["Title"],
"rating": movie["imdbRating"]
}));
filteredList.filter(movie => movie["Rating"] >= 8.0)
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Challenge: Use the filter Method to Extract Data from an Array
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.
filter doesn’t mutate the array it’s working on, it returns a new array.
/* This line does not change filteredList.
It instead evaluates to a new array
containing a subset of filteredList,
specifically those values with a rating
property of at least 8. */
filteredList.filter(movie => movie.rating >= 8.0)
You don’t need quotes around the property names unless they are not valid JS identifiers - some people do this if they were taught JSON and confuse it with a JS object. And you don’t need bracket notation unless the property name is not a valid JS identifier or if it is stored in a variable. In this case, simple dot notation will work.