7. Search for a friend. Wrong output


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Exercise is passed, but output is wrong.
{ firstName: ‘Steve’,
lastName: ‘Jobs’,
number: ‘(206) 666-6666’,
address: [ ‘One Apple Way’, ‘Palo Alto’, ‘CA’, ‘888888’ ] }
{ firstName: ‘Steve’,
lastName: ‘Jobs’,
number: ‘(206) 666-6666’,
address: [ ‘One Apple Way’, ‘Palo Alto’, ‘CA’, ‘888888’ ] }
{ firstName: ‘Bill’,
lastName: ‘Gates’,
number: ‘(206) 555-5555’,
address: [ ‘One Microsoft Way’, ‘Redmond’, ‘WA’, ‘98052’ ] }

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) 666-6666",
        address: ['One Apple Way','Palo Alto','CA','888888']
    }
};
var list = function (friends) {
    for (var firstName in friends) {
        console.log(firstName);
    }
};

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

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


#2

the exercise validates the code, to see the true output you could run your code here


#3

Looks like this thing is very useful, but I don’t understand how to use it)
So my code in JS-window, I push ‘run with JS’ in output-window, and it shows nothing.


#4

its is indeed, if you just simply want to run some code :slight_smile:

make so to have the console-window open, the output-window is a html page. console.log() logs to console, not html page

That is because there is no steve in among your friends, only a Steve


#5

Result is the same.
There no difference if I search for steve or Steve, output is two times Steve and one time Bill.


#6

even on jsbin? Maybe in the exercise because of exercise validition, not on Jsbin, it should output only steves info


#7

sill have problem on jsbin.
it shows nothing in console-window.

but code looks ok?


#8

When i search for "Steve" i get result on console window, can you link me the bin you use? Easier to share a bin then the code


#9

Something new for me)
I just need to send you link like this?


#10

normally that would work, but the forum has problem with the jsbin links since a while. Anyway, like i said, there is not steve:

search("steve");

you have to search for Steve:

search("Steve");

then there is output


#11

Get it.
Thanks for your time!


#13