7/8 Oops, try again. It looks like your search function doesn't return contact information for Steve


#1

I've looked at all of the other answers to this "error", and still cannot see the problem in my own code:

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "0123456789",
        address: ['1 Milky Way','Perth','WA']
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "9876543210",
        address: ['Planet','Space','Cadet']
    }
};

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

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

list(friends);
search("Steve");

Any clues would be of great assistance.

Thanks.


#2

Hi @el_koder

Your code looks like right... Try to delete this

console.log(friends[counter]);

in your search function, and try again to see if it works


#3

Hello, It didn't work for me.. i also have the same issue


#4

Okay, let this serve as a warning to others.

All I had to do was refresh the tab in my browser and it ran perfectly and also passed the Codecademy test.


#6

Hello, I don't understand the syntax of this last 'search' function:
var search = function(name) {
for(var i in friends) {
if(friends[i].firstName === name) {
console.log(friends[i]);
return friends[i];
}
}
};

In the example (1st step) of this exercise the "prop" was used. In another member's examples - "i". Why "i"? Why "prop"? What is that? :smiley: I didn't find any explanation about this before. Thanks in advance!


#7

The instructions say to use an IF/ELSE statement. Why is it when I put in the ELSE to, say, log an error message, it logs the ELSE no matter what. This even happens in the example.

I also really don't understand where the "Name" argument is coming from. There is no function or object or anything called Name here.


#8
var friends=new Object();

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

friends.bill.firstName="Bill";
friends.bill.lastName="Gates";
friends.bill.number="94934922";
friends.bill.address=["200","CA","USA"];

friends.steve.firstName="Steve";
friends.steve.lastName="Jobs";
friends.steve.number="8367290";
friends.steve.address=["230","NY","USA"];

var list=function(one){
 for(var key in friends){
    console.log(key);
 }
}

var search=function(name){
    for(var key in friends){
        if(friends[key].firstName===name){
         console.log(friends[key].firstName+" "+friends[key].lastName+","+friends[key].number+","+friends[key].address);
         return friends[key].firstName+friends[key].lastName+friends[key].number+friends[key].address;
        }
    }
}

This is my code and i can't figure out what's wrong, please help.


#9

el_koder .. tried to use your codes.. nothing wrong. maybe refresh your browser.


#10

I just did this, return'ed outside of IF.

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