Get What You Ask For explainer


The aim of this puzzle: Get the hotel reviews from Grassland and log them all to the console

Walkthrough of the solution: The getData() and findHotels functions are imported. getData() is used to access a database of reviews, and the findHotels function is used as a callback in getData() to retrieve only hotel reviews. Each hotel review is stored as an object with 4 properties: type, city, price, and rating. The printHotel() function will take a hotel review and log all of its properties to the console.

The 1st argument of the getDat() function is the name of a city. The puzzle asks to change this from 'Hopalot' to 'Grassland'. The result of getData() is stored in grasslandHotels. These Grassland hotel reviews can be printed using the printHotel function. Apply the .forEach() method to grasslandHotels, and use the printHotel callback as the argument.

Sample code solution:
(Tap below to reveal)

import { getData, findHotels } from '';

function printHotel(hotel) {
  console.log('type: ' + hotel.type);
  console.log('city: ' +;
  console.log('price: ' + hotel.price);
  console.log('rating: ' + hotel.rating);

let grasslandHotels = getData('Grassland', findHotels);

JavaScript Concepts: Callback Functions, Calling Functions, Code Block (function), console.log(), .forEach(), import

Get what you ask for

Help. I have attempted this and did before checking here. However, I cant build this exact code, or I’m going something wrong.

I changed the Hopalot to Grassland no issue.

Attempted to change the callback function. But no matter what I do there ends up being an empty argument at the end. What am I missing?


I cant seem to figure this one right. I looked at the hint and put that in but it would not allow me to put it 8n exactly. The hint made sense.



When a function like printHotel is created, there are 2 different buttons generated: printHotel and printHotel(). The parentheses at the end mean “run this function”. The button without the parentheses is just a “reference” to the function, like a variable that stores the code without running it. The callback uses the one without parentheses, because it’s like inserting the code from one function into another.

If you scroll the button keyboard to the side, you should see a grey colored printHotel key without parentheses.



What am I missing?


The 2nd argument of getData() should be the callback function: findHotels.

Then on a separate line, you can call .forEach(printHotel) on the grasslandHotels



Ah okay thank you so much. I’ll be playing with this in the playground soon


I think I am having the same problem as other people but am not quite getting the explanations!

One minute it seems to make sense then it’s gone :see_no_evil:


The getData() function takes 2 arguments: A string that’s the name of a city, and a function that instructs what kind of data to get.

Since we want the grasslandHotels variables to store information about hotels in Grassland, we use the string 'Grassland' as the 1st argument. The 2nd argument is the name of a callback function: findHotels.

That will give you: let grasslandHotels = getData('Grassland', findHotels). And grasslandHotels will be an array filled with hotel review objects.

Next, you can use .forEach() on that array: grasslandHotels.forEach(). Inside the .forEach() you can use printHotel as the callback. That will run each array element through the printHotel() function. You can also think of this as applying the printHotel function to each element.



The solution code is not correct. The actual solution code is as follows (I have only referenced the last function call on the page as the rest does not change).


The code in your screenshot looks correct and matches the solution code in the original post. As long as the import statement is still at the top and no other code has been added, this should pass.



Great idea if users could have the option “open this code in the playground”!




Many thanks for your support.
But, I think the solution provided seems incorrect.
Please see below.
Could you be kind to correct it?
That will be a great help for us all neophytes in coding.!
Thank you once again!


It seems your screenshot didn’t upload properly, so I can’t see your code.



Please see attached.


The code screenshot you attached is from the original post in this thread which will solve the puzzle. You may have to scroll to the right to see all of the code, but if you copy this code into the app, it should work. If it’s not, could you post a screenshot of the code you typed inside the app?



Thank you.
I need to scroll to the right to see the full coding.