5/6 Syntax Error?


#1

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
var contactsLength = contacts.length;
for(var = 0; i < contactsLength; i++) {
if(lastName === contacts[i].lastName) {
printPerson(contacts[i]);
};
};
};

search("Jones")


#2

I think your code should look like this :
var search= function(lastName) {
var contactsLength = contacts.length;
for(var i=0; i if (lastName === contacts[i].lastName) {
printPerson(contacts[i]);
}
}
};
search("Jones");
At least it worked for me


#3

oops I'm sorry.I meant
var contactsLength = contacts.length;
for(var = 0; i < contactsLength; i++) {
if(lastName === contacts[i].lastName) {
printPerson(contacts[i]);
}
}
};

search("Jones");


#4

Or maybe :smile:

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


#5

Your problem is var. You haven't declared a variable.

needs to be

 for(var i = 0; i < contactsLength; i++){

hope this helps :smile: