# Basic JavaScript: Profile Lookup Explain

**URL:** <https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221>\
**Category:** General\
**Created:** [April 11, 2020, 1:07am UTC](https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221 "2020-04-11T01:07:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lilmohawk5052](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lilmohawk5052/32/142032_2.png) [@lilmohawk5052](https://forum.freecodecamp.org/u/lilmohawk5052)\
**Post date:** [April 11, 2020, 1:07am UTC](https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221/1 "2020-04-11T01:07:39Z")

</div>

Can someone please explain the solution to this problem? I don’t understand why I have to put return “No such contact”; on the outside of the for loop and not with it. Here is my code:

function lookUpProfile(name, prop){  
// Only change code below this line  
for(var i = 0; i \< contacts.length; i++) {  
if(name === contacts[i].firstName){  
return contacts[i][prop] || “No such property”;  
}  
}  
return “No such contact”;  
}

---

<div class="post-metadata">

**Author:** ![camperextraordinaire](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@camperextraordinaire](https://forum.freecodecamp.org/u/camperextraordinaire)\
**Post date:** [April 11, 2020, 1:32am UTC](https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221/2 "2020-04-11T01:32:53Z")

</div>

When a return statement is executed, the function is immediately exited. How else would you know if the firstName did not exist, if you had not already iterated through all the objects and not found a firstName to match?

---

<div class="post-metadata">

**Author:** ![lilmohawk5052](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lilmohawk5052/32/142032_2.png) [@lilmohawk5052](https://forum.freecodecamp.org/u/lilmohawk5052)\
**Post date:** [April 11, 2020, 1:46am UTC](https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221/3 "2020-04-11T01:46:44Z")

</div>

Thank you so much for that wonderful explanation.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:59pm UTC](https://forum.freecodecamp.org/t/basic-javascript-profile-lookup-explain/371221/4 "2021-06-01T18:59:50Z")

</div>

Closed on June 1, 2021, 6:59pm UTC


