Accessing Objects Properties with Variables

Accessing Objects Properties with Variables
0

#1

Tell us what’s happening:

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 = "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.

Link to the challenge:


#2

Do you have a question?


#3

yes
i used bracket notation in playerNumber with number. eventhough it throwing me a error.


#4

Read the instructions carefully. You are not currently using a variable to access an object property.


#5

Thank you. i got it.


#6

How did you get it because i only need the last area and seem to be getting it here is my code:

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


#7

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”.


#8

okay thanks ive got it