Hi Folks,
I’m not clear why bracket notation works for this, but dot notation doesn’t. See comments in code below. Aren’t these interchangeable?
Thanks,
Starr
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i=0; i < contacts.length; i++){
if(contacts[i].firstName === firstName){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop]; //THIS WORKS
return contacts[i].prop; //THIS DOESN'T WORK
}else {
return "No such property";
}
}
}
return "No such contact";
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Link to the challenge:
https://www.freecodecamp.org/challenges/profile-lookup