Really need help. "7. Search for a friend"


This is my code as currently written. When I run it, the message "Did you create a function called search?" Can someone please show me what the correct code would look like? I can't understand piece by piece instruction, I need to see what it looks like to understand what is happening

var friends = new Object();
friends.bill = new Object();
friends.steve= new Object();

friends.bill.firstName = "Bill",
friends.bill.lastName = "Gates",
friends.bill.number = "404 562-2755",
friends.steve.address = ['One Fake Street','Inglewood', 'CA', '40436']

friends.steve.firstName = "Steve",
friends.steve.lastName = "Jobs",
friends.steve.number = "230 515-7721",
friends.steve.address = ['Two Diamond Road', 'Richmond', 'VA', '12723']

var list = function(obj) {
for (var i in friends) {

var search = function(name) {
for (var prop in friends) {
if(friends[prop].firstName === Bill) {
return friends[prop];




It complains about your search function. If you test your search function, you may find yourself receiving a helpful error message that says in what way it isn't working.


It says Bill is not defined. I'm sorry but this stuff is really not intuitive for me. Can you please show me what the correct code would like? I would understand it much faster. Having two ways of writing it makes it very confusing.


Bill is not defined.

That means you're trying to use the name Bill, but there's no such variable defined.
Look at your function. See any mention of Bill? Should your function specifically know about any Bill? Is Bill defined in that context?

No, I will not just tell you what to do. There are lots of code examples to be googled. But no matter what, you will do mistakes and then you'll have to fix it. You can't write code that you can't fix.


I thought this was defining Bill:

friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "404 562-2755",
address: ['One Fake Street','Inglewood', 'CA', '40436']

The "What you'll be building" page does not have a separate variable for Bill.


That creates a property of friends
No new variable is created.

But again, should that function specifically be aware of any bill?


Is the variable defined outside of the object?


Easy enough to find out isn't it? Try to print it out.
But for the billionth time, what does the search function need to know about bill in particular?


The search function needs to know his first name.


What if I'm not looking for bill? I want to find charlotte.