4/6 Listing Everybody, Multiple output in terminal


#1

Hi, from this code i get multiple outputs in the terminal.

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}
var list = function(){
    var contactsLength = contacts.length
    for (var x = 0; x < contactsLength; x++) {
        console.log(printPerson(contacts[x]));
    }
};

list();

is should get

Bob Jones
Mary Johnson

but i get

Bob Jones
undefined
Mary Johnson
undefined
Bob Jones
undefined
Mary Johnson
undefined

This code is accepted but I'm wondering why this output happens.


#2

@bashiros,

-1

Your printPerson function uses a console.log() statement....
if you then use a secondary console.log() in your list-function
like

 console.log( printPerson(contacts[x]));

you will get a undefined....
You will have to use

 printPerson(contacts[x])

-2

For an explanation, of more output in your display
please read
= http://discuss.codecademy.com/t/6-8-a-question-of-why-i-get-the-result-i-get/10666/10?u=leonhard_wettengmx_n