Accessing Object Properties with Variables

Tell us what’s happening:
I need some help I cannot find out how to do this I’ve been stuck on it for an hour I’d apreciate the help.

Your code so far


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

// Only change code below this line;

var playerNumber = testObj[16];       // Change this Line
var player = playerNumber;   // Change this Line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables

With objects, you can access them using variables:

anObject[someVariable]

what you need to do is assign “Monatana” to the player variable:

var player = testObj[16]

In order to complete the challenge, however, you need to pass a variable instead of the number 16.

 var player = testObj[playerNumber]

All there is left to work out is what you need to pass to playerNumber:

var playerNumber = ????

Hope this helps :slight_smile:

Well, it did but the playernumber is still a problem but thanks for trying :Dᅠᅠᅠᅠ

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

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

console.log(player);```

It is saying assign a number to playerNumber.

So do I assign 16 to playerNumber?

Yes, and then you need to pass playerNumber into the brackets

FINALLY! I got it thank you

// 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

console.log(player);```