Add It to the List explainer

Having issues solving this one…sure the answer is right in front of me, but I just don’t see it…

Hey there, if you’d like to post a screenshot of your code, I can take a look and give you some pointers.

Ben

Here it is.

Great, let’s take a look:

We want the getRatings function to take a list of hotels, and return a list of all of the hotels’ ratings.

The list of hotels is an array of objects that looks something like this:

[
    {
        type: 'Hopaday Inn',
        city: 'Hopalot',
        price: 138,
        rating: 4.0
    },
    {
        type: 'Hoppy Graceland',
        city: 'Bugsville',
        price: 78,
        rating: 3.8
    }
]

We want the function to loop through the array to look at each object individually, .push() the rating property to a new array, then return the array containing just the ratings.

When the puzzle loads, there’s an empty array declared in the function to contain the ratings, and then a return statement that returns the array. Your goal is to add code in between to push each rating to the array.

Hope that clears things up! Let me know if you have any questions.
Ben

I appreciate you helping me with this but I’m not getting it. Is there a way to just get the answer so I can add it to my notes for later?

Sure, scroll up! The answer, plus an explanation, is at the top of every Explainer post.

Also be sure to read the posts from other users in this thread.

– Ben

I feel like the solution explanation is not enough…
Could you please elaborate it?

Try remove the loops and add for loop