7. Why it prints Steve twice?


#1
var friends={};
friends.bill={};
   friends.bill.firstName='Bill';
   friends.bill.lastName='Muray';
    friends.bill.number='568956';
    friends.bill.address=['ulica','adres','dsa456']
friends.steve={};
    friends.steve.firstName='Steve';
    friends.steve.lastName='Jobs';
    friends.steve.number='556545';
    friends.steve.address=['ulica2','adrescz','dsa456'];
    var list=function(friends){
        for(var whatever in friends){
            console.log(whatever);
            }
        }
    var search=function(name){
        for(var whatever in friends)
        if(friends[whatever].firstName===name){
            console.log(friends[whatever]);
            return friends[whatever];
            }
        }

it prints
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] }
["ulica2","adrescz","dsa456"]

why Steve is two times?
when I call function by search("Bill")
it prints
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] }
{"firstName":"Bill","lastName":"Muray","number":"568956","address":["ulica","adres","dsa456"]}


#2

@devcoder96779,

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );


#3

yes i added this
console.log(friends);
console.log("====================");
list(friends);
console.log("==============")
search("Steve");

and now i`ve got

{ bill:
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] },
steve:
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] } }
====================
bill
steve
==============
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] }
{"firstName":"Steve","lastName":"Jobs","number":"556545","address":["ulica2","adrescz","dsa456"]}

so.. still.. why 2x steve and 1x bill for search("steve")? :o


#4

@devcoder96779
Try using

console.log(friends);
console.log("====================");
list(friends);
console.log("==============")
search("Steve");
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

#5

yes I tried. part of console:

== My End ==
== All that is displayed now, is the course-checker ==
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '556545',
address: [ 'ulica2', 'adrescz', 'dsa456' ] }
{ firstName: 'Bill',
lastName: 'Muray',
number: '568956',
address: [ 'ulica', 'adres', 'dsa456' ] }

Why All that is displayed now, is the course-checker shows 2x Steve and 1x Bill?


#6

my problem is exactly the same but i've added a 'third person' and then it shows (the asked, 2x steve and 1x bill, the asked):

{ firstName: 'Julian',
lastName: 'Kiss',
number: '33797326 73489',
address: [ 'here', 'close', '4th street' ] }
{ firstName: 'Steve',
lastName: 'Bye',
number: '364 38989',
address: [ 'there', 'nearby', '8th street' ] }
{ firstName: 'Steve',
lastName: 'Bye',
number: '364 38989',
address: [ 'there', 'nearby', '8th street' ] }
{ firstName: 'Bill',
lastName: 'Hey',
number: '098 6789',
address: [ 'somewhere', 'near', '7th street' ] }
{"firstName":"Julian","lastName":"Kiss","number":"33797326 73489","address":["here","close","4th street"]}


#7

@barbaraaax

https://discuss.codecademy.com/t/7-why-it-prints-steve-twice/32513/2?u=leonhard.wettengmx.n