Contact list search function says it doesn't exist


#1

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

It says "Oops, try again. Did you create a function called search?'' when I hit submit.


var friends = new Object();

friends.bill = new Object();
friends.steve = new Object();

friends.bill.firstName = "Bill";
friends.bill.lastName = "Williaims";
friends.bill.number = "867-5309"
friends.bill.address = [""];

friends.steve.firstName = "Steve";
friends.steve.lastName = "Reeder";
friends.steve.number = "555-5555";
friends.steve.address = [""];

function search(name){
    
    for (friend in friends){
        
        if (friends.friend.firstName === name){
            
            console.log(friends.friend.address);
            return friends.friend.address;
        }   
    }
};

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


#2

Try to call your function, you will see some errors. You have to fix them.

Because of the errors SCT (submission correctness test) is not able to execute the function and that is why it thinks that function wasn't created.

function search(name){ 
    for (friend in friends){
        if (friends.friend.firstName === name){
            console.log(friends.friend.address);
            return friends.friend.address;
        }   
    }
};

search("Steve");
// => TypeError: Cannot read property 'firstName' of undefined

#3

ahh.. yes that makes sense thx


#4

You're very welcome :slight_smile:


#5

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