4.dispaying~~something so unbelivable,TKS


#1


I passed it actually, but I couldn't really realise what it's going on.
That's because the "HINT" below
Here's how to define a function:

var myFunction = function(param1) {
// Do something

But I had done the same thing, it totally didn't work.
Until I amended my code.
Here my code is

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
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
};
printPerson(contacts[0]);
printPerson(contacts[1]);


Replace this line with your code.


#2

I did the same thing and it worked. What is unbelievable here? :slight_smile:


#3

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

You defined two objects bob and mary.

var contacts = [bob,mary]; // missed ;

You defined array contacts where you put created objects.

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

You created function which takes one parameter and print firstName and lastName.

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

You called function printPerson.

Do you need smth else to explain? Describe your problem if you didn't find the answer.


#4

sorry, my bad,
the HINT :
var myFunction = function(param1) {
// Do something

but I did the samething ,it didn't work,

However, it worked below,

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


#5

sorry, my bad,
the HINT :
var myFunction = function(param1) {
// Do something

but I did the samething ,it didn't work,

However, it worked below,

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


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

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

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}

console.log( list() );

Check your code with mine. Maybe you have some syntax errors.


#7

OH, I see,
Thank you so much, mate~!


#8

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