I can NOT do it


#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 = [bob, mary];
for(printPerson = 0;printPerson < contactsLength.length; printPerson++);
};

list(printPerson);

//Instruction
We'll be creating a function that lists all of the users.

Create a function called list that does not take any parameters.
At the start of the function, define a variable to store the number of items in the contacts array. Call it contactsLength.
All of the items in an array are numbered, starting at 0. To cycle through all of the elements of the array, create a for loop that cycles from 0 up to one less than the number of items in the contacts array.
Inside of the loop, add code to call printPerson, passing in the element of the array that the loop is currently at.
At the very bottom of the file, call the list function. The list function should then loop through every member of the contacts array and print its information.


#2

Here you don't store the length of the array in contact lengths, but a list.

Also use contacts.length not [bob, mary].length so that the function still works if new contacts are added.


#3

please!! write wholly


#4

Sorry I misread you code.

You created a for loop that doesn't do anything.

First you should not use the printPerson as a variable in the for loop, because that's already the name of a function.

Instead of

for(printPerson = 0;printPerson < contacts.length; printPerson++);

use

for(i = 0;i < contacts.length; i++) {

// here goes the code that you want to be executed
//for every i from 0 to contactsLength.length
}

Hint: You can use contacts[i] to acces the ith contact.