6. List em All issue


#1

I'm being allowed to the next stage, but it's not printing the way the instructions say that it should.

Here is the code:

var friends = new Object();
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "250-972-0000",
address: ['One Microsoft Way', "Banger", 'WA', '98052']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "255-890-0101",
address: ['One Apple Way', 'IPhone', 'CA', '90210']
};
var list = function(friends) {
for (var info in friends) {
console.log(info);
}
}

And here is what is printed out:

bill
steve
{"firstName":"Steve","lastName":"Jobs","number":"255-890-0101","address":["One Apple Way","IPhone","CA","90210"]}

Can anyone explain what's going on?

Cheers,
Chris


#2

@shubanshii,

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

I'm sorry, but I don't understand.


#4

Your code on its own doesn't print anything. Because it doesn't say that anything should be printed. It defines some values and that's it.

The submission test to the exercise however, is doing some printing.

If you want to print something in particular you'll have to add code that does that.


#5

Thanks for the reply. I think I'm getting warmer. See below:

var friends = new Object();
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "250-972-0000",
address: ['One Microsoft Way', "Banger", 'WA', '98052']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "255-890-0101",
address: ['One Apple Way', 'IPhone', 'CA', '90210']
};

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

list(friends);

It prints out:
bill
steve
bill
steve

Why does it print out Bill and Steve twice? How do I make it to where the list function handles the printing exclusively?


#6

Maybe it doesn't. See @leonhard.wettengmx.n's suggestion


#7

Okay I think I kind of get it now. So the course checker is doing it, the code isn't telling it to print. I don't understand what his console.logs are for or there significance.


#8

I've tried yours, it worked