6/6 We made a friend : Passed, with undefined error


#1

Hello, i've got a strange error notification on my code, i've passed the exercice but the console log "undefined"

here comes the code :

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);
}

//Create a search function
//then call it passing "Jones"

search = function(lastName)
{
    for(i=0; i<contacts.length;i++)
    {
        if(contacts[i].lastName ===lastName)
        {
         printPerson(contacts[i]);
        }
        else
        {
         console.log("not found");
        }
    
    }
};

var add = function(firstName, lastName,email, phoneNumber){
    contacts[contacts.length] = {
    firstName : firstName,
    lastName : lastName,
    email : email,
    phoneNumber : phoneNumber 
    };
};


add("henri","fardeau","henri.fardeau@gmail.com","012345987");
search("Jones");
function list() {
	for (var i = 0; i < contacts.length; i++) {
		printPerson(contacts[i]);
	}
}
console.log(list());

Do you know whats wrong?


#2

This is where the undefined is coming from. .log() has no return value. Consider also that printPerson() is logging output.


#3

You're right, many thanks.

I need more sleep.


#4

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