Got stuck with the function


#1


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


SyntaxError: Unexpected end of input


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
        },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(206) 443-4444",
        address: ['Apple drive', 'San Francisco', 'WA', '98052']
        }
};

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


#2

You have 3 mistakes in your search function
1. change parameter from firstName to some else, maybe to a "name", "x" or some else (it's not a mistake, it is simply just confusing)
2. comparison should be made with ===, not ==
3. after === shouldn't be boolean, you have to put the "name" or "x" from point 1 in there because you are comparing parameter given in a function call below this code.


#3

Thanks! I've changed it but still it tells me that there is "SyntaxError: Unexpected end of input"

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 443-4444",
address: ['Apple drive', 'San Francisco', 'WA', '98052']
}
};

var list = function(){
for (var name in friends){
console.log(name)
}
}
var search = function(x){
for (name in friends){
if(friends[name].firstName===x){
console.log(friends[name]);
return friends[name];
}
else {
console.log("Not found in the list")
}
}


#4

I already found my mistake


#5

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