Basic JavaScript - Profile Lookup

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
function lookUpProfile(name, prop) {
for (let x = 0; x < contacts.length; x++) {
if (contacts.firstName === name) {
if (contacts.hasOwnProperty(prop)) {
return contacts[prop];
} else {
return “No such property”;
}
}
}
return “No such contact”;
}
i does not want to work

function lookUpProfile(name, prop) {
  for (let i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === name) {
      if (prop in contacts[i]) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    }
  }
  return "No such contact";
}

Your browser information:

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

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

Hmmm, When I copy and paste your solution in the assignment it passes.

The beginning of the function is already written for you above the “enter code” comment. Maybe make sure the beginning of function is not duplicated. Also, maybe make sure nothing about the array above the line has been changed

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