Printing what I need to, PLUS last object content. Why?


#1



My code output passes and I can move on, but there's unexplained stuff at the end as well:

bill
steve
{"firstName":"Steve","lastName":"Creeper","number":"804-344-5621","address":["155 Blue St.","Lapis","WA","23122"]}

I don't want this to print out. Why do I get this?


var friends = new Object();

friends.bill =
{
    firstName: "Bill",
    lastName: "Harcen",
    number: "804-903-7821",
    address: ["132 Red St.", "Redland", "WA", "23412"]
};

friends.steve =
{
    firstName: "Steve",
    lastName: "Creeper",
    number: "804-344-5621",
    address: ["155 Blue St.", "Lapis", "WA", "23122"]
};

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


#2

I'm a little bit confused about your question, but from my understanding, you're just printing out everything in friends, because friends is utterable. This is actually what you want to do for this lesson.

are you expecting just firstName of Steve and bill to print out? Because when you write a for each loop, it doesn't matter what you call the variable, (firstName, friend, person, etc.), the same thing will print out.

edit: I didn't think about what @factoradic said before he said it, but he's right, just didn't consider it.


#3

This extra "stuff" at the end is a result of codecademy tests running in your browser.

If you want to see the real output of your code you should use a different environment, for example JS Bin or repl.it.


#4

Thanks! That answers my question.


#5

You're very welcome :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.