Stuck on using map method

Tell us what’s happening:

Hello this is my first post on this forum. I don’t want the answer, just advice/hints to help me along. Thank you in advance.

I think I’m close, maybe, to solving this. This is the output of my code:

[ ‘{“title”: Inception, “rating”: 8.8}’,
‘{“title”: Interstellar, “rating”: 8.6}’,
‘{“title”: The Dark Knight, “rating”: 9.0}’,
‘{“title”: Batman Begins, “rating”: 8.3}’,
‘{“title”: Avatar, “rating”: 7.9}’ ]

I still have single quotes that shouldn’t be there. Also, I commented out the console.log(JSON.stringify(ratings)) line just to see how it would look but that is part of the challenge that we’re not supposed to edit. This is what it looks like with JSON.stringify

["{“title”: Inception, “rating”: 8.8}","{“title”: Interstellar, “rating”: 8.6}","{“title”: The Dark Knight, “rating”: 9.0}","{“title”: Batman Begins, “rating”: 8.3}","{“title”: Avatar, “rating”: 7.9}"]

which I get is because I’m using template literals, but I’m unsure of what else to use. I’m thinking maybe the arrow function needs to be changed. I think I provided enough info but if more is needed let me know! :slight_smile:

Your code so far


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.

// The global variable
var watchList = [
    "Title": "Inception",
    "Year": "2010",
    "Rated": "PG-13",
    "Released": "16 Jul 2010",
    "Runtime": "148 min",
    "Genre": "Action, Adventure, Crime",
    "Director": "Christopher Nolan",
    "Writer": "Christopher Nolan",
    "Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
    "Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
    "Language": "English, Japanese, French",
    "Country": "USA, UK",
    "Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
    "Poster": "",
    "Metascore": "74",
    "imdbRating": "8.8",
    "imdbVotes": "1,446,708",
    "imdbID": "tt1375666",
    "Type": "movie",
    "Response": "True"
    "Title": "Interstellar",
    "Year": "2014",
    "Rated": "PG-13",
    "Released": "07 Nov 2014",
    "Runtime": "169 min",
    "Genre": "Adventure, Drama, Sci-Fi",
    "Director": "Christopher Nolan",
    "Writer": "Jonathan Nolan, Christopher Nolan",
    "Actors": "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow",
    "Plot": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
    "Language": "English",
    "Country": "USA, UK",
    "Awards": "Won 1 Oscar. Another 39 wins & 132 nominations.",
    "Poster": "",
    "Metascore": "74",
    "imdbRating": "8.6",
    "imdbVotes": "910,366",
    "imdbID": "tt0816692",
    "Type": "movie",
    "Response": "True"
    "Title": "The Dark Knight",
    "Year": "2008",
    "Rated": "PG-13",
    "Released": "18 Jul 2008",
    "Runtime": "152 min",
    "Genre": "Action, Adventure, Crime",
    "Director": "Christopher Nolan",
    "Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
    "Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
    "Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
    "Language": "English, Mandarin",
    "Country": "USA, UK",
    "Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
    "Poster": "",
    "Metascore": "82",
    "imdbRating": "9.0",
    "imdbVotes": "1,652,832",
    "imdbID": "tt0468569",
    "Type": "movie",
    "Response": "True"
    "Title": "Batman Begins",
    "Year": "2005",
    "Rated": "PG-13",
    "Released": "15 Jun 2005",
    "Runtime": "140 min",
    "Genre": "Action, Adventure",
    "Director": "Christopher Nolan",
    "Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
    "Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
    "Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
    "Language": "English, Urdu, Mandarin",
    "Country": "USA, UK",
    "Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
    "Poster": "",
    "Metascore": "70",
    "imdbRating": "8.3",
    "imdbVotes": "972,584",
    "imdbID": "tt0372784",
    "Type": "movie",
    "Response": "True"
    "Title": "Avatar",
    "Year": "2009",
    "Rated": "PG-13",
    "Released": "18 Dec 2009",
    "Runtime": "162 min",
    "Genre": "Action, Adventure, Fantasy",
    "Director": "James Cameron",
    "Writer": "James Cameron",
    "Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
    "Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
    "Language": "English, Spanish",
    "Country": "USA, UK",
    "Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
    "Poster": "",
    "Metascore": "83",
    "imdbRating": "7.9",
    "imdbVotes": "876,575",
    "imdbID": "tt0499549",
    "Type": "movie",
    "Response": "True"

// Only change code below this line
var ratings = [];
for(var i=0; i < watchList.length; i++){
  ratings.push({title: watchList[i]["Title"],  rating: watchList[i]["imdbRating"]});

let ratings = => `{"title": ${movie.Title}, "rating": ${movie.imdbRating}}`)

// 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/92.0.4515.159 Safari/537.36

Challenge: Use the map Method to Extract Data from an Array

Link to the challenge:

Why are you making a string? You should map each element to an object instead of a string.

I would look up on MDN how to return an object literal from an arrow function with an implicit return statement.

1 Like

A good example - JavaScript | MDN

1 Like

I still kinda struggle with vocabulary and up to this point have only talked to my close friend who happens to be a programmer about JS, so to answer why… my thought process that led to that was “why won’t ‘title’ and ‘rating’ appear? oh I know, wrap it with `` and ${} and then it will!” MDN articles are constantly in my tabs but this proves I need to look closer at them than I have been. I struggle with the logic sometimes, but I figure the more I do things the more times I will know what to do rather than guess like with this lol. thank you both and have a good evening/day.

Yea, the vocabulary can be tricky, but knowing the vocabulary makes it much easier to use Google to find pieces of syntax you’ve forgotten. Keep practicing and it’ll come to you with time. Good job getting the code to pass!

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