7. Search for a Friend


#1


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

Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected token var

I can't figure out which var is not necessary in my code.


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "206 555-5555",
        address: ["One Microsoft Way","Redmond","WA","98052"],
    },
    steve: {
        firstName: "Steve",
        lastName: "Martin",
        number: "302 555-5445",
        address: ["725 Vandever Avenue","Los Angeles","CA","10276"],
    },
    helen: {
        firstName: "Helen",
        lastName: "Featherer",
        number: "813 347-3523",
        address: ["13906 Henson Circle","Tampa","FL","33625-}"],
        }
    var list = function(friends) {
        for(var x in friends) {
            console.log(x);
            
    var search = funtion(name) {
        for(var key in friends) {  
            if(friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
}
}
};
list(friends);
search("Helen");


#2

The unexpected var is the start of the search() function. The list() function body is not closed.

    var list = function(friends) {
        for(var x in friends) {
            console.log(x);
    };    // this curly brace is missing

Both functions are currently inside the object enclosure, which will cause an error to be raised. Move them outside, to just below the object closing curly brace.


#3

Thank you for your response. I took the var out and it didn't make a difference. I'm confused about your other comment. Can you please clarify?


#4

It was not necessary to remove the var keyword, which is necessary, btw, just insert the missing curly brace as indicated.

After the helen object, add one more closing brace to close the friends object enclosure.

var friends = {
    bill: {},
    steve: {},
    helen: {}
};

var list = function () {

};

var search = function () {

};