7. Search for a Friend - been staring but i don't see my mistake


#1

Heya!

So, I have been looking at it for the past 30 mins and it's not making sense as to what I have done wrong. :frowning:

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "0101010101",
address: ['Microsoft Manor','Reynald','CA','90210']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "10101010101",
address: ['iPhone Villa','Macintoch', 'CA','90211']
},
};

var list = function (i) {
    for (var prop in i){
        console.log(prop);
    }
};

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

This is the error I am getting "SyntaxError: Unexpected token {"

Thank you loads :slightly_smiling:


#2

@microslayer11184,

Have a close look at

fuction

AND

In your search function
have a look at the property-key you are using in your comparison


#3

@leonhard_wettengmx_n

Hello, I've read what you have said.
I've tried to word it out simply to understand as well.

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

Is it saying
Search for name (ie bill)
For the variable property in function friends.
If the property of the first name is equal to name (bill)
Print (bill)
Else return...

Am I wrong? I want to understand the theory so I found it best to type it out.


#4

@microslayer11184,
Change your

 (friends[prop].firstname === name)

into

(friends[prop].firstName === name)

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


#5

Thank you :slightly_smiling:
Turns out i had written function wrong as well.

Again, thank you :smiley: