31/33 What is wrong in this code?


#1

What is wrong here?
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 = new snoopy();
snoopy.species="beagle";

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


#2

Hi @blogmaster24137
You just have to change this

var species = snoopy.species;

var age = snoopy["age"];

Hold on :wink:


#4

...why is age supposed to be a string?

why isn't it just snoopy[age]?


#6

// It'll woks
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"];