} else if(name !== contacts[i].firstName) {
return "No such contact";
Your problem is here. You are that if (on the first run through or whatever) that if that name does not equal that particular member’s first name, you want to return "No such contact";
Remember that return
doesn’t just exit the for
loop, but completely exits the function. So, unless the name asked about is the first one in contacts, then it will bale out of the function - it won’t even check any others. You need to find out of there is a way that instead of exiting the function, that you can just “continue” on to the next iteration of the for
loop.
When I change that line, your code passes for me.