// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line;
var playerNumber = testObj[16]; // Change this Line
var player = "Montana"; // Change this Line
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.
You didn’t declare playerNumber with a value and you didn’t use it anywhere. "16" is not the number 16, but the string of characters “16”. Also, you shouldn’t be hardcoding a value there at all because the challenge is “Accessing Object Properties with Variables”.
Guys, I still have a question about this one.
There are 2 goals of the exercise as I understand it:
Use the playerNumber variable to look up player 16 in testObjusing bracket notation.
Then assign that name to the player variable.
And then if you look into solution:
var playerNumber = 16; // I do not see any bracket notation during this look up. Am I missing something?
var player = testObj[playerNumber]; // this one is clear
While reading the task I was going for that solution (but obviously it didn’t worked):
var playerNumber = testObj[16];
var player = playerNumber;
Here’s the question (if you’ve missed it in the comment above) - I do not see any playerNumber variable look up in testObjusing bracket notation
Most likely I’m not getting a task properly or there’s a chance that task is incorrectly formulated?
When it says “use the playerNumber variable… Using bracket notation” it means that the variable should be used in the lookup expression. What you have would probably br phrased something like “use bracket notation to assign a value to playerNumber”. The point of this exercise is to show you that when you are using a variable to lookup an object property, you need to use bracket notation.