trying to do this exercise:
Use the playerNumber variable to look up player 16 in testObj using bracket notation. Then assign that name to the player variable.
// Setup
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
not to sure about this one, i thought it might be:
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber (16); // Change this line
var player = testObj[player]; // Change this line
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber = 16; // Change this line
var player = testObj["Montana"]; // Change this line
“Montana” is the value of testObj.16, not a variable.
You have a variable that holds a property name of testObj. You need to use that variable to access a value in in testObj.
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
console.log(myBreed); // "Doberman"
I see that we assing the value of 'Hunter ’ to the variable of myDog, so in the exercise we are assigning the value of ‘16’ to variable playerNumber…
then we use the bracket notation to assign ‘playerNumber’ to player.
var dogs = {
Fido: 'Mutt',
Hunter: 'Doberman',
Snoopie: 'Beagle'
};
var myDog = 'Hunter'; // myDog is the string 'Hunter'
var myBreed = dogs[myDog]; // same as doing dogs['Hunter'] just using a variable
console.log(myBreed); // "Doberman"
It sounds like you’ve got it. What’s your code? (Sometimes it is best to reset the code if you’ve been trying a lot of different things, because other changes can sneak their way into the boilerplate.)
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber = 16; // Change this line
var player = testObj["16"]; // Change this line
and I have tried it without quotations as well.
the message I get is:
You should be using the variable