Profile Lookup about the for loop

Tell us what’s happening:
Why should I put the “No such contact” outside the for loop?

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.

Link to the challenge:

Because the for loop will not run if there are no contacts. IE if contacts.length == 0

Thank you, Josh. I checked code explanation, and got your mean.
Originally, my solution is to put the “No such contact” right after the first if statement like this

 for(var i = 0; i < contacts.length; i++){
      if(contacts[i].firstName === name){
          return contacts[i][prop];

          return "No such property";

*           return "No such contact";*
*               }*

I realized that it only run the for loop once, then end the function.

If you want to ask a question about one of the solutions from the guide, please link the guide and indicate which solution you are asking about and don’t post the full working solution.

We are trying to cut down the number of full working solutions found in the forum

thank you for understanding