Contact List - List'em All!


#1


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


My code logs excess information when I run it.

can someone help explain why?


var friends = {} ;
    friends.bill  = {
        firstName: "Bill",
        lastName: "Squire",
        number: "(408)111-2222",
        address: ['101 Code Way','San Jose','CA']};
    friends.shane = {
        firstName: "Shane",
        lastName: "Kistner",
        number: "(408)222-3333",
        address: ['123 Shane Way','San Jose','CA']};
    friends.pat = {
        firstName: "Pat",
        lastName: "Moroney",
        number: "(858)222-1111",
        address: ['321 Gay Ave','Brooklyn','NY']};
    friends.steve = {
        firstName: "Steve",
        lastName: "Guy",
        number: "(408)555-4321",
        address: ['9098 Somewhere Blvd','Los Gatos','CA']
    
        };

var list = function (object) {
    for (var enumerable in object) {
        console.log(enumerable);}
};

var search = function(name) {
    for (var enumerable in friends) {
        if(friends[enumerable].firstName === name){
            console.log(friends[enumerable]);
            return friends[enumerable];
    }
  }
};    

list(friends);
search("Steve");


#2

When you find a match you're logging the entire 'friend' to the console. That includes all of their properties.

When you submit this exercise, the codecademy magic testing machine tries your function with a few different inputs to see how it responds which is why it logs so many outputs (2 Steve's, a Bill and a Steve).

Can you find a way to explicitly log each of your properties using your above 'list' function? You may need to adjust the console.log statement within it.


#3

I am stumped.

I did run this same code in node & get 1 output. Which was nice.
But now I want to find out how to explicitly log each property.


#4

Currently your list function logs the property names of a provided object. Try to get it to log 'property propertyValue' each iteration.

Recall that you can access the object's property values with the syntax obj[prop].


#5

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