Search for a friend.(Please tell me where am I going wrong ?)


#1



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


Oops, try again. Did you create a function called search?


var friends = {
bill : {
    firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way','Redmond','WA','98052']   
    },
steve : {
    firstName: "Steve",
        lastName: "Jobs",
        number: "(180) 000-0000",
        address: ['Macintosh','Malibu','CA','44042']
    }
};
var list = function(friends) {
    for(var key in friends) {
        console.log(key);
    }
}
var search = function(name) {
    if(friends[key].firstName === Name) {
        console.log(friends[key]);
        return friends[key];
    }
}


#2

Hi you shoud call the function search() then its missing the for loop in your seacrh function


#3

var friends = {
bill : {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve : {
firstName: "Steve",
lastName: "Jobs",
number: "(180) 000-0000",
address: ['Macintosh','Malibu','CA','44042']
}
};
var list = function(friends) {
for(var key in friends) {
console.log(key);
}
}
var search = function(name){
for(var key in obeject){
if(friends[key].firstName === name){
console.log(friends[key]);
return friends[key];
}
}
}
list(friends);
search("steve");

Still getting an error:
Oops, try again. Did you create a function called search?


#4

this line

for(var key in obeject)

where you have obeject you should put friends which is the name of the object


#5

■■■■ it...I missed it... thanks a lot for spotting it! :slight_smile:


#6

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