Accessing Properties, Part 2


#1

My code:

// Take a look at our next example object, a dog
var dog = {
  species: "greyhound",
  weight: 60,
  age: 4
};

var species = dog["species"];
// fill in the code to save the weight and age using bracket notation
var weight = dog['age'],
var age = dog['weight']

I'm not sure what is wrong here but the error is a bit off.

Error:

The error is on the last line, I don't know how to fix this. Any help would be really appreciated :smiley:


#2

here:

var weight = dog['age'],

why do you have a comma at the end of this line?


#3

I can't believe such a small mistake can make a whole code go wrong. Thanks for your help! It saved me :smile:


#4

welcome in the wonderful world of programming :wink:


#5

There are two other options as well, though what @stetim94 told you is accurate for the Codecademy course.

// multiple variable declarations can use a single 'var'
var species = dog.species,
    age = dog.age,
    weight = dog.weight;

// ES2015 destructuring is the bomb
var { species, age, weight } = dog;

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.