7/8 help


#1

var friends = {
bill: {
firstName: "bill",
lastName: "gates",
number: "(245) 555-5555",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
},
steve: {
firstName: "steve",
lastName: "jobs",
number: "(345) 555-5555",
address: ['Two Apple Way', 'Redmond', 'CA', '95014']
}
};
var list = function(friends) {
for (key in friends) {
console.log(key);
};
};
var search = function(name) {
for (var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};
search("steve");

it says my function doesn't return contact information for steve


#2

This code works fine when I try to run it. Does the output provide anything else as an error?


#3

am also facing the same problem


#4

var friends = {
Bill: new Object(),
Steve: new Object(),

list : function () {
for (var x in friends) {
    console.log(x)
}
},

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

};

friends.Bill.firstName = "Bill";
friends.Bill.lastName = "Gates";
friends.Bill.number = "800-555-8888";
friends.Bill.address = ['some address, some address'];

friends.Steve.firstName = "Steve";
friends.Steve.lastName = "Someone";
friends.Steve.number = "900-555-3853";
friends.Steve.address = ['some address, some address', 'third addy line'];

friends.search("Steve")

This is my slightly different take, but still having problems with "Steve" apparently not providing the correct results. Any help appreciated.


#5

I am encountering the same problem. I cannot find any errors in my code but it still gives me the same error code every time.
"Oops, try again. It looks like your search function doesn't return contact information for Steve."

Here is my code

//Creating Contact List
var friends = {};
friends.bill= {
firstName: ("Bill"),
lastName: "Blankocheck",
number: "(407)123-1234",
address:["unknown street","Sometown","66677","WA"]
};
friends.steve= {
firstName: ("Steve"),
lastName: "Plakiotis",
number: "(321) 444-8889",
address: ["666 satans street","orlando","32801", "Fl"]
};

//List Function
var list=function(obj){
for(var key in obj)
{
console.log(key);
}
};

//Search and Display Function
var search = function(name){
for(var key in friends){
if(friends[key].firstName===name){
console.log(friends[key]);
return friends[key];
}
else
{
console.log("They're not in our book");
return "They're not in our book";
}

}};

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


#6

I had a similar problem which turned out to be a typo... check caps, commas, and semicolons maybe?


#7

@jnagle02

In your var list function, you should have a "var" before key"

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

Also codeacademy says you're missing Steve, so in its answer check it is looking for a capital Steve (and a capital Bill instead of lowercase steve lowercase bill). Once you capitalize the names in your code you should get the desired output the lesson is looking for.


#8

@javacyclecss

In your search and display function remove the return statement:

return "They're not in our book";

I am not too clear on why that is not valid, but it's for some reason taking this response instead of picking up Steve.


#9

@joanneyeung

Thank you three times. I appreciate this so much.

One question.

If that extra return line had been in a regular javascript word processor and not in codecademy do you think it would have behaved the same way?


#10

In his original code. Why did you put that?


#11

@javacyclecss

I also couldn't understand why your code wouldn't work. I have a feeling that it may be just the way Codecademy checks the final answer of your output, but I can't say for certain. Here, I also use this as a resource sometimes: https://repl.it/languages/JavaScript
That site lets you run your script to test as if in a native environment and on running your code it seems to check out fine. Hope that helps.


#12

@joanneyeung thanks for that repel.it site, it logged my code the way It was supposed to, rather than repeating my objects multiple times to the console.