-1

I got stuck in this Accessing Objects Properties with Variables exercise, Can somebody please explain me what to do, thanks.

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

// Only change code below this line;

var playerNumber ;       // Change this Line
var player = testObj;    // Change this Line

1 Answers1

0

not sure exactly what you're trying, but you can access as follows:

var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};
var player = testObj["12"];
document.write(player);

Get the property value by adding [] on the end of the object and giving the right property name.

There are a few other ways, too: see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects.

tempranova
  • 929
  • 9
  • 13