3/6 Code is not working


#1

This is my Code, I wonder why it's not working:

var printPerson = function(person) {
person.firstName = firstName;
person.lastName = lastName;
console.log(firstName + " " + lastName);
};

printperson(contacts[0]);
printperson(contacts[1]);

#2

Hi you forgot to uppercase the P of person inside your function when you called it.

printPerson

#4

Thank you, But still not work because of the function problem...


#5

Can you post all your code.


#6

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];

// printPerson added here
var printPerson = function(person) {
    person.firstName = firstName;
    person.lastName = lastName;
    console.log(firstName + " " + lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);

#7

You function printPerson should ne like that

var printPerson = function(person) {
    console.log(bob.firstName + " " + bob.lastName)
    console.log(mary.firstName + " "+ mary.lastName)
};


}

#8

the point of this course is print using array name. It's work if we do this:

`
var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);

But i want to understand what is the problem with:

`
var printPerson = function(person) {
person.firstName = firstName;
person.lastName = lastName;
console.log(firstName + " " + lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);
`

`


#9

The problem is here dude:

var printPerson = function(person) {
** firstName = person.firstName;**
** lastName = person.lastName;**
console.log(firstName + " " + lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);


#10

I understand that and i post the right code! The problem is WHY it's wrong and why this logic is not working,,,


#12
      You wrote different thing:

console.log(person.firstName + " " + person.lastName) etc.

What I wanted to say is that you have to define firstName to be equal to person.firstName (not vice versa)
so you wrote:

var printPerson = function(person) {
person.firstName = firstName;
person.lastName = lastName;
console.log(firstName + " " + lastName);
};

in the line 2 and 3 you said that whenever computer sees
person.firstName it will read it as firstName. But it is not
said that it should read firstName as person.firstName. So
that's why your console.log command didn't work. You just
need to change places of person.firstName = firstName to firstName = person.firstName

That is my opinion though) I am also just begginer and I might be wrong