Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables

Tell us what’s happening:
Describe your issue in detail here.
I have an issue to solve this problem.When I run it shows undefined.Please help me to solve this problem.

  **Your code so far**

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

// Only change code below this line
function playerPrefix(str){
var s = 'player';
return s + str;
}
var testPlayer = playerPrefix('Number');
var playerNumber = 16;   

console.log(testObj[testPlayer]);
console.log(testPlayer)
console.log(playerNumber)
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Accessing Object Properties with Variables

Link to the challenge:

I suggest you reset the challenge, what you should do is much less complicated than what you need
you just need to change the two lines with the comments following this:

Set the playerNumber variable to 16 . Then, use the variable to look up the player’s name and assign it to player .

1 Like