Whats wrong with my code?


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



It would help others provide an answer if you could paste all the code from the exercise.

Just looking over what you've provided, I've noticed a couple of issues:

  • The variable contactsLength is not referenced correctly in your for loop, you have contactsLenght instead.
  • The array contacts that you're referencing doesn't exist in the above snippet so it can't complete.

If we could get the entire code snippet you're trying to run that would be helpful!