6. List 'em all - Correct, but more output than needed


#1

Code:

var friends = new Object();

friends.bill = {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-555",
        address: ['Address1', 'Address2'],
};

friends.steve = {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(408) 555-555",
        address: ['Address3', 'Address4'],
};

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

Output:

bill
steve
{"firstName":"Steve","lastName":"Jobs","number":"(408) 555-555","address":["Address3","Address4"]}

This turns out 'bill' and 'steve' correctly, but there are extra lines that come out. Why?


#2

Running your code doesn't print any of that actually. You've defined friends and a function list and that's all your code does. They are not used in any way, your function isn't called.

console.log is still pointing at your console when the submission test runs, it's calling your function which prints out bill and steve. After that, for whatever reason, Codecademy prints out the last value that was used in your code.. or SOMETHING like that.. I really think that the function "should" get printed but..nope. if you add 5 at the end of your code or just before your function, then you'll find that gets printed..


#3

bill steve c маленькой буквы


#4

Ahh thanks for the explanation ionatan!

After adding this line to the code

list(friends);

everything turns out fine. -----

** Though to be real nit-picking though :sweat_smile: when I do 'list(friends);' in the console, an 'undefined' will still return after giving the correct answers. Not the end of the world, but I just curious as to where the extra piece might be coming from.

Much thanks!


#5

More or less the same explanation there :confused:


#6

if i use list(friends[0);
it prints one bill, steve

if i use list(friends);
it prints double bill, steve, bill, steve

which is correct answer?