Basic JavaScript - Profile Lookup

hello,
The code above passed though i can understand something:
we are asked to check both name and property,
while the code seem to only be checking if name is a contacts’ firsName but not also the contacts’ property.
can you explain ? sorry for bad english for i m not a native speaker, hope you understand.

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

lookUpProfile(“Akira”, “likes”);

// Setup
const 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 i = 0; i < contacts.length; i++){
  if (contacts[i].firstName === name){
    return contacts[i][prop] || "No such property";  
  }
}
return"No such contact";
  // Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; rv:105.0) Gecko/20100101 Firefox/105.0

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

What do you think that this line that you wrote is doing?

1 Like

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