31 Properties, bracket notation


This looks simple but I’m having trouble with it.

Set the global variable species to be snoopy’s species and the variable age to be snoopy’s age. For one use dot notation and the other use bracket notation

I already know snoopy’s age and it’s set to snoopy.age, so I can’t see how to use bracket notation to set it to the new age variable.

This is the code I’ve got so far:

var snoopy = new Object();
snoopy.species = “beagle”;
snoopy.age = 10;

// save Snoopy’s age and species into variables
// use dot notation for snoopy’s species
var species = snoopy.species;

// use bracket notation for snoopy’s age
var age = snoopy[age];

and it’s saying:
"Oops, try again.
It looks like you didn’t save snoopy’s age into age!

What am I missing?


Bracket (subscript) notation treats keys as strings:

var age = snoopy['age'];