Declaring functions with 'var'


#1



https://www.codecademy.com/en/courses/building-an-address-book/0/4?curriculum_id=506324b3a7dffd00020bf661#


I get, "SyntaxError: Unexpected token }". Is there a reason I can't use the var form of declaring my 'list' function here?


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 (x=0,(x < contactsLength - 1),x++) {
        printPerson(contacts[x]);
        };
};
list;


#2

Your for loop is not correct. Should be:

for (x=0; x < contactsLength; x++) {
   printPerson(contacts[x]);
};
list(); // here you also have error - missed ()

#3

Thanks very match, Denys.


#4

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