# The console.logs return whats asked but when run the tests fail every one

**URL:** <https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 17, 2021, 2:17am UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757 "2021-02-17T02:17:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeysoon](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeysoon/32/206042_2.png) [@jeysoon](https://forum.freecodecamp.org/u/jeysoon)\
**Post date:** [February 17, 2021, 2:17am UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757/1 "2021-02-17T02:17:28Z")

</div>

When i console.log results it retrieves me exactly whats asked but with a minor change i saw.  
In arrays returned instead of using " " im getting ’ ’ i dont know if that may be the problem.

```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
contacts.forEach(contact => {
    if(contact.firstName = name && contact.hasOwnProperty(prop)){
        console.log(contact[prop]);
            return contact[prop];
    }
})
return "No such contact"
// Only change code above this line
}

// lookUpProfile("Akira", "likes");
//lookUpProfile("Kristian", "lastName")
lookUpProfile("Sherlock", "likes")

```

```
**Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 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:** ![Naomi](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/naomi/32/422181_2.png) [@Naomi](https://forum.freecodecamp.org/u/Naomi)\
**Post date:** [February 17, 2021, 2:27am UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757/2 "2021-02-17T02:27:00Z")

</div>

![image](https://global.discourse-cdn.com/freecodecamp/original/3X/5/a/5a52a2d34ce86d8e8b868b9bbf146443002695c9.png)

When I test it, I see a lot of extra things being logged. Let’s break it down a bit.

`contact.firstName = name ` This bit in your `if` condition is a syntax error (a common one, I do it myself quite often). You’re using the assignment operator `=` instead of an equality operator `==` or `===`.

Next, you’re using `forEach`, which is a good way to iterate through an array. However, this comes with some pitfalls. `forEach` takes a function callback as its first parameter. That function has its own return statement, which you are using to `return contact[prop];`. The problem here is that value doesn’t get passed up to the outer function, and that `return` statement doesn’t terminate your outer function.

So instead, your function hits it’s _own_ return statement and gives back `"No such contact"`.

If we remove the `console.log(contact[prop])` and console.log your function call:

 ![image](https://global.discourse-cdn.com/freecodecamp/original/3X/0/d/0d910f387527ec5d91a89735ad9e33cc51589c35.png)

---

<div class="post-metadata">

**Author:** ![jeysoon](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeysoon/32/206042_2.png) [@jeysoon](https://forum.freecodecamp.org/u/jeysoon)\
**Post date:** [February 17, 2021, 2:35am UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757/3 "2021-02-17T02:35:25Z")

</div>

Okeeeey, didn’t realize about that, very silly mistake on my part the ’ = ’ you are absolutely right, ill try to keep on using the same ‘tools’ with classes without trying new stuffs like forEach because what at first glance may be the same is clearly not. But now i know is not working the same under the hood . Thanks nhcarrigan!

---

<div class="post-metadata">

**Author:** ![Naomi](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/naomi/32/422181_2.png) [@Naomi](https://forum.freecodecamp.org/u/Naomi)\
**Post date:** [February 17, 2021, 3:17am UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757/4 "2021-02-17T03:17:40Z")

</div>

Hey the best way to learn this stuff is by trying it. 😁

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 18, 2021, 3:18pm UTC](https://forum.freecodecamp.org/t/the-console-logs-return-whats-asked-but-when-run-the-tests-fail-every-one/446757/5 "2021-08-18T15:18:32Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
