Contact List. 7. Search for a friend. (Syntax error)


#1

I've overlooked this code many times and it's still showing an error. Please, if you can, point out the issue. Thank you very very much.

var friends = {};
    friends.bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(111) 555-5555",
        address: ["One Microsoft Way','Redmond','WA','98052"]
    };
    friends.steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(222) 777-7777",
        address: ["One Microsoft Way','Redmond','WA','98052"]
    };
var list = function(friends) {
    for (var key in friends) {
            console.log(key);
    }
};
var search = function(name) {
    for (var key in friends) {
        if (friends[key].firstName === name {
            console.log(friends[key]);
            return friends[key];
        } else {
            console.log("couldn't find them");
        }
    }
};

#2

No closing parentheses for this if statement.


#3

in this lesson you are explained multiply ways to define objects, you choice one of them, but you made a small mistake here:

friends.bill: {

you should use a equal sign:

friends.bill= {

you used the dot notation, but used a colon instead of a equal sign. and @bandit already found the other mistake.


#4

Thank you for the response. I've made the said change, but I'm still receiving a syntax error.


#5

Thank you for the response. I've made the change, but I'm still receiving the same syntax error.


#6

Have you corrected the other error that @stetim94 pointed out?


#7

can we see an updated version of your code? I only showed the change for bill, obviously the same change needs to be made for steve


#8

var friends = {};
    friends.bill= {
        firstName: "Bill",
        lastName: "Gates",
        number: "(111) 555-5555",
        address: ["One Microsoft Way','Redmond','WA','98052"]
    };
    friends.steve= {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(222) 777-7777",
        address: ["One Microsoft Way','Redmond','WA','98052"]
    };
var list = function(friends) {
    for (var key in friends) {
            console.log(key);
    }
};
var search = function(name) {
    for (var key in friends) {
        if (friends[key].firstName === name {
            console.log(friends[key]);
        };
            return friends[key];
            
        } else {
            console.log("couldn't find them");
        }
};

#9

now you made matters worse, this was what you had:

var search = function(name) {
    for (var key in friends) {
        if (friends[key].firstName === name {
            console.log(friends[key]);
            return friends[key];
        } else {
            console.log("couldn't find them");
        }
    }
};

except there was a small problem in this line:

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

the ( doesn't have a matching closing ):

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

i don't understand why you made it worse for yourself by doing the other changes


#10

I've closed the parenthesis on if (friends[key].firstName === name { , also, I went to the original code and made the changes from bandit, along with the changes you've mentioned. The code now works!!!! Thank you guys!