Profile Lookup Challenge- Please, why is my solution not working?

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

It would help to have the challenge link to this problem.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I think if you search for the challenge on the forum you will find the answer. Remember that a return statement ends function execution.


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