Search for a friend..Function not found


#1


Ive literally looked at every QA of this my code looks identical helllllp

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


var friends = new Object(); {

friends.bill = new Object(); {
    
    friends.bill.firstName = "Bill",
    friends.bill.lastName = "MC",
    friends.bill.number = 720,
    friends.bill.address = ["Infinite Loop","sw69 069"]
}   
    
friends.steve = new Object(); {
    friends.steve.firstName = "Steve",
    friends.steve.lastName = "JayZ",
    friends.steve.number = 690,
    friends.steve.address = ["Deez nutz","Sww www"]
}
};

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


};

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


#2

your search and list function seems fine, i would take a look at how your objects are constructor, i can't even decide which you are using (object constructor vs literal notation), i recommend you take a second how to construct the objects properly


#3

I thought thats how you use object constructor...


#4

no, the object constructor doesn't use curly brackets ({}), you can simply create the objects with the object constructor:

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

and then add the property's:

friends.steve.firstName = "Steve"

curly brackets are only used for the literal notation.


#5

Sorry sir, Your code may be awesome in your point of view. but you will get unexpected result as you think. it might be helpful to you

var list = function (friend) {
// declare a variable as key to access
for (var key in friend) {
console.log(key);
}

};

var search = function(name){

for (var key in friends){

 if(friends[key].firstName === name){

     console.log(friends[key]);
     return friends[key];

 }

#6

■■■■ straight my code is awesome... thanks tho


#7

thanks

.
..

.
.
.
............


#8

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