Please help me, on why it would not work if there’s “console.log” on my return statement? - Profile Lookup

Tell us what’s happening:

Describe your issue in detail here.
Here’s my code:

Your code so far

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

let data = lookUpProfile("Akira", "likes");

console.log(data);

And I checked the first solution because I’m frustrated on why my code is not working and it took me two days to finally check the solution, it TURNS OUT, all I have to do is remove “console.log” on every return statement, or am I missing something else?

Please help me, on why it would not work if there’s “console.log” on my return statement?

Hello Hettdo, console.log is used to output a message to the console and return undefined, so it will not work if you use it to return a statement, that why you have to remove it and return directly your statement, and take the return and use console.log to output it, check the developer mozila docs console: log() static method - Web APIs | MDN

3 Likes

Hello Aka-Dev, thank you so much for your explanation and the link.

This really opens up a lot of new ideas for me, regarding return statements and when to use console.log.

1 Like