Sorry, my initial question was not very good because your code example isn’t formatted very well and I was fooled a little.
function lookUpProfile(name, prop) {
// Only change code below this line
for (let i = 0; i < contacts.length; i++) {
if (contacts[i]["firstName"] === name) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
} else {
return "No such contact";
}
}
// Only change code above this line
}
Now that we have better formatting, how many times will your for loop execute? Remember, a return statement immediately stops the function and returns a value.
my for loop would run 4 times , evaluating the first name property of all the objects in the contacts array and checking if they are equal to name. But when i run the test it fails and i’ve gone through the code a thousand times but can’t seem to see what is wrong.