4. Listing Everything


#1

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 = i; i };
printPerson(contacts[i]);
};


#2

Hey @tagjumper20201! Your problem is Your last for loop. You probably didnt see this.

Change this:

To this:

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

Merry Christmass!:evergreen_tree:


#3

Thnks but the computer print ous: Oops, try again. There was a problem with your syntax.---> SyntaxError: Unexpected token =

Do you know what's the problem ? :smile:

Merry Christmass too :evergreen_tree:


#4

sorry change the above to this:

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

My fault. Thankyou


#5

Tank you for your help :smile:


#6

:laughing: !!!!! :smile:


#7

I I know that we created a variable called contacts.lengths = contactslength, but we never call the variable contactslength, so why do we have to define that variable to equal the length of the contacts array? is it just because in order for the coputer to understand the code, that it needs to be defined?


#8

the variable is in the loop :smile:


#9

No, it doesn't necessarily need to be defined.

contacts.length works in the for loop too...I think that whoever wrote the instructions to this module just decided to show that we could use a variable instead of the length property


#10

actually, there's a good explanation for declaring it as variable


#11