What's the correct output?

Tell us what’s happening:
I have one last task " Your code should return the correct output after modifying the watchList object."

Your code so far

// Only change code below this line
  var averageRating = watchList.filter(wl => wl["Director"] == "Christopher Nolan");

  averageRating = averageRating.reduce((obj, ar) => {
    obj[ar["Title"]] = ar["imdbRating"];
    return obj;
  }, {}); 

averageRating.Inception = parseFloat(averageRating.Inception);
averageRating.Interstellar = parseFloat(averageRating.Interstellar);
averageRating.['The Dark Knight'] = parseFloat(averageRating.['The Dark Knight']);
averageRating.['Batman Begins'] = parseFloat(averageRating.['Batman Begins']);
var sum = averageRating.Inception + averageRating.Interstellar + averageRating.['The Dark Knight'] + averageRating.['Batman Begins']

averageRating = sum / 4;
  
  


  // Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15.

Challenge: Use the reduce Method to Analyze Data

Link to the challenge:

It looks like you attempted to hardcode the solution. This often does not work with our test suite.

1 Like

How can I loop to find all the numbers and make them real numbers?

// Only change code below this line
  var averageRating = watchList.filter(wl => wl["Director"] == "Christopher Nolan");

  averageRating = averageRating.reduce((obj, ar) => {
    obj[ar["Title"]] = ar["imdbRating"];
    return obj;
  }, {}); 
var nums = [];
const values = Object.values(averageRating);
var i = 0;
while (i < values.length) {
nums.push(parseFloat(values[i]));
i++;
}
var sum = 0;
console.log(nums);
i = 0;
while (i < nums.length) {
sum += nums[i];
i++;
}
averageRating = sum / 4;
  
  


  // Only change code above this line

Made a loop, but still not working.

Found the solution:
averageRating = sum / 4;
had to be
averageRating = sum / nums.length;