# Please help me,I don't understand why my code is not working

**URL:** <https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 12, 2020, 6:25pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036 "2020-08-12T18:25:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 12, 2020, 6:25pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/1 "2020-08-12T18:25:22Z")

</div>

**Tell us what’s happening:**

**Your code so far**

```js

// Setup
var contacts = [
{
    "firstName": "Akira",
    "lastName": "Laine",
    "number": "0543236543",
    "likes": ["Pizza", "Coding", "Brownie Points"]
},
{
    "firstName": "Harry",
    "lastName": "Potter",
    "number": "0994372684",
    "likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
    "firstName": "Sherlock",
    "lastName": "Holmes",
    "number": "0487345643",
    "likes": ["Intriguing Cases", "Violin"]
},
{
    "firstName": "Kristian",
    "lastName": "Vos",
    "number": "unknown",
    "likes": ["JavaScript", "Gaming", "Foxes"]
}
];

function lookUpProfile(name, prop){
// Only change code below this line
for ( var x = 0; x < contacts.length;x++){
if (contacts[x].firstName === name){
    if(contacts[x].hasOwnProperty(prop)){
        return contacts[x][prop]
    } else {
        return "No such property"
    }
} else {
    return "No such contact"
}
}
// Only change code above this line
}

lookUpProfile("Akira", "likes");

```

**Your browser information:**

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

**Challenge:** Profile Lookup

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 12, 2020, 6:28pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/2 "2020-08-12T18:28:20Z")

</div>

> [@harshalc](#):
>
> ` return "No such contact"`

Hi and welcome to the forum!

I would think carefully about when you want to `return` this phrase. Have you checked all names at this point in your code?

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [August 12, 2020, 6:28pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/3 "2020-08-12T18:28:40Z")

</div>

You forgot to tell us what’s happening. If you can describe the problem you’re having, we’re happy to help you figure it out.

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 3:51am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/4 "2020-08-13T03:51:30Z")

</div>

Yes,and when console.log the latter arrays in contacts,it does not read them,that is the function only reads the array containing Akira,but does not the ones of Harry,Sherlock and Kristian.

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 3:52am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/5 "2020-08-13T03:52:05Z")

</div>

When I console.log the latter arrays in contacts,it does not read them,that is the function only reads the array containing Akira,but does not the ones of Harry,Sherlock and Kristian.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 13, 2020, 3:55am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/6 "2020-08-13T03:55:19Z")

</div>

Exactly. So, what does that if statement do, in words?

What would make it stop after a single loop iteration?

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 3:56am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/7 "2020-08-13T03:56:56Z")

</div>

Oh so basically it is not looping?

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 3:58am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/8 "2020-08-13T03:58:32Z")

</div>

oh so basically it is not looping?How can I loop it?

---

<div class="post-metadata">

**Author:** ![samanviekk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/samanviekk/32/134434_2.png) [@samanviekk](https://forum.freecodecamp.org/u/samanviekk)\
**Post date:** [August 13, 2020, 4:11am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/9 "2020-08-13T04:11:37Z")

</div>

your code is correct. Only thing is you didn’t print(console .log) the output.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 13, 2020, 4:22am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/10 "2020-08-13T04:22:26Z")

</div>

No, the code is not correct.

@harshalc, your if statement that is checking the name is the problem. The question is why.

Any time your code encounters a `return` execution stops. You code, as, written, will always stop execution on the first loop iteration. This isn’t quite what you want, right?

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 5:34am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/11 "2020-08-13T05:34:46Z")

</div>

@JeremyLT Oh now I understand the problem,so I have to place the last return statement out of the for loop ,correct?

---

<div class="post-metadata">

**Author:** ![harshalc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@harshalc](https://forum.freecodecamp.org/u/harshalc)\
**Post date:** [August 13, 2020, 5:37am UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/12 "2020-08-13T05:37:40Z")

</div>

Thanks a lot,it helped

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 13, 2020, 1:29pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/13 "2020-08-13T13:29:53Z")

</div>

You got it! Nice work!

---

<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, 12:38pm UTC](https://forum.freecodecamp.org/t/please-help-me-i-dont-understand-why-my-code-is-not-working/415036/14 "2021-06-01T12:38:40Z")

</div>

Closed on June 1, 2021, 12:38pm UTC


