Listing everybody


#1


I don't understand why this code doesn't run.


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

//why is this code not running?

var list = function() {
    var contactsLengnth = contacts.length;
    for( i = 0; i < contactsLength, i++ ) {                 // Uncaught SyntaxError: Unexpected token )  on this line. Why?
        printPerson(contacts[i]);
    };
    
};

list();


#2

var contactsLengnth = contacts.length;

check the spelling of the variable.there is a difference between the name of the variable you took and the name of the variable you used for for...loop

for( i = 0; i < contactsLength, i++ )

put a ; instead of a ,


#3

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