Why are there so many bugs in the Java script course? (Building address book task)


#1

I'm working my way through the course, but I keep coming across errors when there shouldn't be any. Here my code works perfectly in the console but I keep getting the message:

Oops, try again. Make sure that the list() function still exists! Your code threw the following error when checking if you called list(): Error: Line 48: Unexpected token ILLEGAL

What is going on? What have I done wrong?

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 add = function(firstName, lastName, phoneNumber, email) {contacts[contacts.length] = {
    firstName: firstName,
    lastName: lastName,
    phoneNumber: phoneNumber,
    email: email
    }
};


var contacts = [bob, mary,];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

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


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


add("Fred", "Durst", 07971828264, "freddurst@gmail.com");

list();

#2

Put telephone number as a string value:

add("Fred", "Durst", "07971828264", "freddurst@gmail.com");

#3

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