Can someone help me find my syntax error


#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 = for (i = 0; i < contacts.length; i++){
printPerson(i);
}
}
list();


#2

You can't assign a for statement to the variable. And why would you like to do this?

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

#3

they ask to define a variable to store the number of items in the contacts array. Call it contactsLength. then to create a for loop that cycles from 0 up to one less than the number of items in the contacts array. what do they mean by this?


#4

define a variable to store the number of items in the contacts array. Call it contactsLength.

var contactsLength = contacts.length;

create a for loop that cycles from 0 up to one less than the number of items in the contacts array

for(var i = 0; i < contactsLength; i++) {

}

#5

Ohhh i get it now haha thanks


#6

You're welcome :slight_smile:


#7

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