Don't understand what this sentence mean.. (Lesson : Accessing Object Properties with Variables)

So actually I have finished the challenge, here’s my code snippet:

// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;
var playerNumber = 16;       // Change this Line
var player = testObj[playerNumber];   // Change this Line

But I don’t understand what this sentence mean

Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name .

Especially the one in the bold,

I’d be glad if someone could explain it to me

They are saying that this line:

var player = testObj[playerNumber];

could not be:

var player = testObj["playerNumber"];

because we do not want a property on the testObj called “playerNumber”. The playerNumber is a variable containing the property key we want, in this case 16. If we put testObj["playerNumber"]; it would not look for key 16, but key “playerNumber”.

It’s the difference between using playerNumber as a variable name or a string. In this case, we want a variable name.

I got it!! Thank you so much :slight_smile:

And just to be clear, we wouldn’t normally use something like testObj["playerNumber"] where we write out an explicit string with the quotes like that. The only time we need to do that is if the property name is not a valid JS identifier, like if it starts with a number or has a space it it. It is however very common to see this bracket notation using a variable.