Syntax error, where are you?


#1


7.Search for a friend


Syntax error: syntax error


var friends ={
 bill: {
 firstName: "Bill",
 lastName: "Gates",
 number: "(206) 555-5555",
 address: ['One Microsoft Way','Redmond','WA','98052']
 },
 steve: {
 firstName: "Steve",
 lastName: "Jobs",
 number: "(306) 222-2222",
 address: ['One Apple Blvd', 'Cupertino', 'CA', '95014']
 },
 dan: {
 firstName: "Dan",
 lastName: "Danielson",
 number: "(709) 123-4568",
 address: ['One Mounty Dr', 'Badger', 'NL', 'A0H 0B7']
 },
 harold: {
 firstName: "Harold",
 lastName: "Parsons",
 number: "(478) 000-1111",
 address: ['400 Hog Rd', 'Fayetteville', 'AR', '72704']
 },
 jayram: {
 firstName: "Jayram",
 lastName: "Santaguri",
 number: "(214) 323-4841",
 address: ["24234 Rambo Ct', 'Plano', 'TX', '75075'"]
 }
};
var search = function(name) {
    for(var firstName in friends) {
        if(friends[name].firstName === name) {
            console.log(friends[name]);
            return friends[name];
        }
        else {
            return("Sorry man! Haven't found a thing");
        }
    }
            
    };
};


#2

Please print the code I need to change and how, with a brief explanation.


#3

the very last closing curly bracket:

};

it doesn't match to anything, remove it.

the variable you use in the for loop:

for(var firstName in friends)

will hold the objects (bill, steve, dan, harold and so on) which you go to search through, so firstName is what should be between the square brackets

A function ends the moment a return keyword is reached, in your case the first run of the loop


#4

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