I can't spot the error in this code, please can anyone help?


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

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

var add = function(firstName, lastName, email, phoneNumber){
contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
};
};

add("lawrnce", "oputa", "lawrenec@gmail.com", 0980187474);
list(contacts.length);


#2

@lawreneagles,

if you start a number Value with a zero,
the Javascript interpreter is going to interprete the number as an octal....
google search
javascript number starting with zero site:stackoverflow.com
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates

So change

add("lawrnce", "oputa", "lawrenec@gmail.com", "0980187474");

The list() function
does not take an argument
so change to

list();