Using map method challenge

how do i push in objects containg informations into my new array???
Tell us what’s happening:

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.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0

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

Link to the challenge:

Can you please share your code?

You shouldn’t be using push at all.

That is not your code. That is just the link to the challenge. What code have you written so far?

const ratings = => watchList) iam trying to replace the for loop on the challenge with map method

Your callback needs to make new array elements out of the old ones. What is the format the challenge asks for you to use with these new objects?

This can’t work since watchList isn’t defined in the scope of the callback.

A callback in just a function. It needs to have variables in scope and a return value, just like any other functions

you mean destructuring??

I mean… What are you trying to make? You need to understand what you are trying to build before picking syntax to do the task. These tasks are too complex to guess the syntax without understanding the end goal.

Syntax follows after developing a plan, which comes after understanding your goal. This is why I’m trying to get you to explore/explain what the new array elements should look like.

1 Like

i am trying to use map on watchList to assign a new array of objects to the ratings variable

I’m aware of what the challenge wants. Repeating the high level summary of the instructions isn’t very useful.

What should the new objects inside of the array look like?

It’s literally impossible to do this challenge if you can’t describe what you want the new objects to look like. Do you know which part of the instructions are telling you what the new objects need to look like? Do you understand what that part means? If you don’t, that’s the first thing we need to work on.

the new object should have the key title with the name of the film,and also a rating key with with the imdb rating

Ok. That we can work with.

You need a callback function that takes the original objects in the array and makes the new objects you just described.

Forgetting about the map for a second, how do you do this?

function filmCallback(oldFilmObject) {
  let newFilmObject = {};
  // to do....
  return newFilmObject;

What should this function look like?

Once you have this function, the rest is much easier.

add the newFilmObject in the parenthesis??

Maybe. How would you do that?

i will add it to the parenthesis,and call it

What would that code look like?

function filmCallback(oldFilmObject, newFilmObject) {
  let newFilmObject = {title: title,imdb:rating };
  // to do....
  return newFilmObject;

Ok, but the variables title and rating don’t exist. Where are you going to get those values?

i just had to console .log the code and see what it looks like.this is what i got SyntaxError: redeclaration of formal parameter newFilmObject

Why did you add an extra function argument? You can’t pass in the newFilmObject into a function that is supposed to make the newFilmObject. That can’t work