3. Displaying People (2 kinds of solutions?)


#1


I don't know why the right answer is only to use "person.firstName" and "person.lastName". Why can I not to use "contact[x]" in the the function printPerson as I coded as below?


https://www.codecademy.com/en/courses/building-an-address-book/0/3?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. Did you create a function called printPerson?


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 = [];
contacts[0] = bob;
contacts[1] = mary;

// printPerson added here
var printPerson = function (x) 
    {
    console.log(contacts[x].firstName + " " + contacts[x].lastName);
    };
    
    printPerson(0);
    printPerson(1);


#2

because of how the exercise is validated:

var test = {
	firstName: " ",
	lastName: " "
}

try {
	printPerson(test);
} catch (ReferenceError) {
	return "Did you create a function called printPerson?";
}

the exercise calls the printPerson function with test (a dictionary with a first and lastName) your function can't handle this.


#4

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