Help appreciated!


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. It looks like your list function isn't printing the right output.


var list = function(friends) {
    for (var friends in friends["firstName","lastName","number","address"]){
        console.log(friends["firstName","lastName","number","address"]);
    }
};


#2

@devace71301 you have two problems here...

Your suppose to repeat just in friends..:

for (var key in friends){

Hard to give a hint there.... And then since you have your key

console.log(friends[key]);

More importantly do you understand what it does?


#3

Is it for listing purpose? For example, when somebody is searching a certain person, these information would show up if the name matches the name that's in the contact.

I am sorry, but I didn't really get it. Do I just put key in there? Or do I replace key with firstName, lastName, number, and address?


#4

Sorry for lateness... so basically i dont know what your exercice is suppose to do... but i told you this:

var list = function(friends) {
    for (var key in friends){
        console.log(friends[key].firstName);
    }
};

So basically above you can see there is key. Well that key starts with the 0 index itterating through the friends object.. so at 0's index there is going to be bill gates so essentially its doing:

console.log(friends[0].firstName);

which translates to...

console.log(bill.firstName);

which translates to:

"Bill Gates"

Now then it goes to second.. which is steve jobs:

console.log(friends[1].firstName);

which translates to...

console.log(steve.firstName);

which translates to:

"Steve Jobs"

Understand(It basically itterates over the object which in this case is bill and steve. Key is the index number it is itterating in)?


#5

Thank you! I think I understand what you are saying. But I tried it like the code below and it still gives me an error message. And it only prints out Bill and Steve.
Here's the link: https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661#

var list = function(friends) {
    for (var key in friends){
        console.log(friends[key].firstName);
    }
};

#6

Yes it is suppose to print Bill and Steve because you are printing the firstName of the "objects" bieng itterated. But for this lesson your just suppose to do:

var list = function(friends) {
    for (var key in friends){
        console.log(friends[key]);
    }
};

Basically you dont need to print firstname but you just need to print the actual whole key, as im preety sure it said in instructions(i may be wrong).


#7

It says that it will print out all the entries we have in our friends object (so I guess that means everything)
However, I did tried that but it didn't work. It did print all the informations in the console. But it still gives an error: Oops, try again. It looks like your list function isn't printing the right output.

https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661#


#8

Have a look at the instructions, what do they say to print for each entry in friends?


#9

@devace71301 i mislead you sorry.. your suppose to print the actual firstname of all objects..

var list = function(friends){
  for (var key in friends) {
  console.log(friends[key].firstName)
  }   
}

then dont forget to pass friends as arguent


#10

03. In the loop, use console.log to print out the key.


#11

That's alright! But when I was trying to call the function, it tells me an ReferenceError: key is not defined
But I did define key as a variable in the for loop. I tried to put it in the for loop part, but my browser crushed so I guess it makes it an infinite loop. So I really don't know what is wrong here. I am sorry that I have so many questions.

var list = function(friends) {
    for (var key in friends){
        console.log(friends[key].firstName);
    }
};

list(friends[key]);

#12

Thank you! I just saw that.


#13

the problem is when you pass it as an argument..y you do:

list(friends)

first of all key is not visible outside that for loop. second you must pass the whole object to itterate through it.


#14

Well, that doesn't really work either...


#15

For the third time:
Instructions are to print the keys, they don't even mention first names.


#16

I tried, it didn't work. But it did print all the information in the console


#17

You're not printing the keys though


#18

I am confused. So how should I print the keys?


#19

console.log(key)


#20

When I put it outside of the loop, it says that key is not defined.