Can't call the function, names aren't defined


#1

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

When I try and call the function, it states that the names aren’t defined:

ReferenceError: bill is not defined.

Thanks for the help.



var friends = {
 bill:{
    firstName:"Bill",
    lastName:"Gates",
    number:"(864) 258 - 5829",
    address: ["1452 Microsoft Way","Redmond", "WA", "34839"]
    },
 steve:{
    firstName: "Steve",
    lastName: "Jobs",
    number: "(456) 987 - 9765",
    address: ["9840 Apple Reaserch", "Defrode", "Ca", "23444"]
    },
 lucas:{
    firstName: "Lucas",
    lastName: "Henry",
    number:"(250) 378 - 1524",
    address:["3870 Yell st", "BC", "Canada", "20343"]
    },
 elliot:{
    firstName: "Elliot",
    lastName: "Wallbridge",
    number: "(250) 741 - 2345",
    address: ["4920 Ogon st", "BC", "Canada", "49396"]
    }
};

var list = function(name) {
    for (var firstName in friends) {
        console.log(firstName);      
    }
};

console.log(list);


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

search(bill);





#2

In the call of your search() function
you are using an argument =bill=

The interpreter will interprete =bill= to be a VARIABLE…
So either you define the VARIABLE bill and then call your search() function
like

var bill = "bill";
search(bill);

or

you call the search() function
like

search("bill");


#3

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