For this exercise, this piece of code with return contacts[i][prop]; works
> function lookUpProfile(name, prop){
>
> // Only change code below this line
>
> for (var 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";
>
> }
>
> }
>
> return "No such contact";
>
> // Only change code above this line
>
> }
but this doesnt :
> function lookUpProfile(name, prop){
>
> // Only change code below this line
>
> for (var 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";
>
> }
>
> }
>
> return "No such contact";
>
> // Only change code above this line
>
> }
Why is this so?
I thought javascript objects could be accessed with both . operator and [ ] operator ?