Exercise 6 - please help


Can someone help me with this exercise? It seems totally nonsensical.

You need to create a function that will print the friends names and information to the console log if I understand correctly (this is never explained in detail so my guess is as good as yours).

Second, it asks you to use a "for (var key in object)" but doesn't explain what the variable key is or is supposed to refer to. So I don't know whether to write "key" or something else or how this loop works. How does it know which object's keys to target? Am I supposed to replace "key" with the actual name of the key I want it to refer to? It just makes no sense.

Third, I also have absolutely no idea what to put inside the for loop besides console.log(something).

Finally, why does the list function have to take a parameter? It says to put one parameter but there's no clue as to what this parameter is or should be.

I need help - the lack of information in this one is really infuriating. :frowning:


function list(???)
    for (var key in object)


the for/in loop is explained in the lesson?
To do this, we'll want to use a bit of new syntax: a for/in loop.

It looks like this:

for (var key in object) {
  // Access that key's value
  // with object[key]

The "key" bit can be any placeholder name you like. It's sort of like
when you put a placeholder parameter name in a function that takes

key is a variable which will hold the items in the friends object:

for (var key in friends){

see how key will hold the objects inside the friends object? The for in loop does everything for you. Now you can use key to access the objects in friends object:


hope this helps. Your function doesn't need a parameter, why would it? You can access the friends object from inside the function


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