Tell me what is wrong please

Tell us what’s happening:

Your code so far


// 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";
  }
}
}
return "No such property";
// Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; itel A16 Plus) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Mobile Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:

Hey @ychris!

Here is your problem

2 Likes

How should I remedy the problem

Why did you write No such property twice?

I didn’t run your code but would like to point out that you have a space before hasOwnProperty

2 Likes

I try removing the last one but still failed

That’s a good catch.
The test suite still accepts it when I ran the code with the correct solution.

1 Like

You don’t need to remove the last return statement but the text is wrong.

FCC instructions
If name does not correspond to any contacts then return "No such contact" .

Which of the return statement did you remove cause I removed the last one but still failed

Pay close attention to the text and the instructions. It doesn’t make sense to repeat " No such property" twice.

1 Like

The last return must be “No such contact”.
Also, remove the space in property checking line.

contacts[x].hasOwnProperty(prop)

This will work.

2 Likes

Thanks it work after removing the space and adding up the no contact

3 Likes

Hello , how can avoid this message
"Maximum stack size exceeded " from this recursion.
function A(x,n){
if(x === 0){
return x;
setTimeout(A);
} else {
return 3 + A(x, x/n);

 }

}
console.log(A(4,2));

Even when I set time out am still having the message

Whenever you get that message it’s because the function keeps calling itself and never reaches the base case. If you ran this code in a debugger you will see that call stack just keeps growing until it hits its limit.

If you have further questions, on this problem please open a new topic because this current question is off topic from the original post.

1 Like

There is probably an infinite loop