Javascript List 'em all!


#1



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


the code prints everything inside the friends object. i.e firstname..lastname,number adress,,of both stever and bill.

 

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond','WA', '98052']
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "1 (907) 123-4567",
        address: ['2101 Walvery Street', 'Palo Alto', 'CA 94301']
    }
};

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

list(steve);


#2

It's a little unclear what you want the code to be doing differently. "All objects but not one" - I can't make any sense out of that.


#3

the code prints everything inside the friends object. i.e firstname..lastname,number adress,,of both stever and bill.


#4

Okay. Sure. What's the problem though? In terms of how it should behave differently.


#6

i want it to print just the firstname of bill and steve.how do i do dat ? need a better understading of for...in loop


#8

Then you would loop through each contact, and with each contact you would then print their first name.

Are you sure that's what the instructions ask for though? What do the instructions say to print?


#11

You probably shouldn't be mentioning bill explicitly anywhere but in your definition of that contact.
Read the instructions you just pasted carefully. It does not say to print first names, it says to print something else.


#13

ohkay for now just leave the instructions...if i have to print the value of key firstname for each object within friends object. how do i do dat?


#28

ohkay so u mean i need to use another index variable..to print the value of the firstName property...something like friends[key].firstName[0] or friend[key][0] ?


#33

This is what we built for a friends object (if we followed the instructions):

var friends = {
    bill: {},
    steve: {}
};

The list() function is a simple utility to output the KEY names in the friends object.

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

There is no need to complicate matters when nothing more is expected.