6/6 Unexpected token "["


#1

Hi! When I run the code, I get,"SyntaxError: Unexpected token [".
Can somebody please help me out? Thank you so much!
Here is my code:

var add = function(firstName, lastName, email, phoneNumber){
var contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
}
}
add("Angelika", "Trump", "fake@email.com.edu", "62226251");
console.log(list());

Thank you once again!


#2

Hey @dragonwizard22! I dont know why you added contact.length but your not suppose to.. Its not the correct syntax so just delete this piece of code from your code()

)

Hope this helped!


#3

Hi! When I delete the contacts.length, my new contact will not be added and the result will be:
Bob Jones
Mary Johnson
undefined

Isn't the contacts.length required to ensure that the new contact will be added at the back of the array?


#4

You can just use it like an Object way like i did:

    var Amanuel = new Object();
    Amanuel.firstName = firstName;
    Amanuel.lastName = lastName;
    Amanuel.email = email;
   contacts[2] = Amanuel;

in the Add function then just call it like this:

add("Amanuel" , "Bogale" , "abogale2@gmail.com" , 44323132412);

Hope this helped!


#5

Hmmm... I'm sorry. I did that and still got the same result. :confused:


#6

del "var" in the piece of code "var contacts[contacts.length]" :wink: