Works but i do not unerstend output


#1



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


As topic says, i get "undefined" even if i uncomment return, i did try to comment last console.log but first lines appers as undefined anyway. Thank you for your help.


var friends = new Object();
    friends.bill = new Object();
        friends.bill.firstName = "Bill";
        friends.bill.lastName = "Bilson";
        friends.bill.number = "123321123";
        friends.bill.address = ["One Way", "Red Keep", 23];
    friends.steve = new Object();
        friends.steve.firstName = "Steve";
        friends.steve.lastName = "Steveson";
        friends.steve.number = "123999123";
        friends.steve.address = ["Two Way", "Black Keep", 4];
     friends.rob = new Object();
        friends.rob.firstName = "Rob";
        friends.rob.lastName = "Robson";
        friends.rob.number = "55559123";
        friends.rob.address = ["For Way", "Dont keep", -3];         
        
    var list = function(friends)
    {
        for (var list in friends) {console.log(list);}
    };
    
    
    var search = function(name)
    {
        for (var key in friends)
        { 
            if (friends[key].firstName === name) 
                {console.log(friends.name);
           //  return friends[key];
                }             
            }
    };
    
    
    search("Rob");


#2

Hi this line

console.log(friends.name);

should print friends[key] like the return statement


#3

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