Trouble with very basic Javascript exercise

Code:
var WEIGHT_KEY = 'weight';

var person = {
  name: 'Ryan',
  weight: 350
};

var weight = person[WEIGHT_KEY];

If you want to refer to the property of the object defined by WEIGHT_KEY, you have to it it using bracket notation ([]). Using dot notation assumes that you are actually providing the name of the property, not a variable referring to it.

Also the actual property in the object, WEIGHT_KEY, was incorrectly named. It should be weight. The reason is that the example says suggests that WEIGHT_KEY refers to the property of the object, in this case the 'weight' property.

Hope I explained that ok. :)
 
Back
Top Bottom