Plz help : Accessing Object Properties with Variables

Plz help : Accessing Object Properties with Variables
0.0 0

#1

Tell us what’s happening:
plz can someone help me , im stuck here , i don’t know where is the problem.

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


#2

playerNumber is the variable that should be used as the property name, and should be set to the number that you want to retrieve (16 in this case).


#3

Question says that playerNumber should be the properties of testObj ( in this case is a number 16), then only you can assign it to access the value .
// 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


#4

@dollamaker To add to the above replies, playerNumber is a variable that will be used to get the name of a player. To get the name of a player in testObj, one must use the player’s number.

  1. Create a playerNumber variable set to a player’s number
  2. Use the playerNumber variable to get the player’s name from testObj