Using Bracket Notation to access properties

Dear all,

In this exercise:
1 - Let’s use bracket notation to access the value of 'Active Mission' from the spaceship object in the code editor. Create a variable isActive and assign the spaceship ‘s 'Active Mission' property to it.

and then:

2 - Using bracket notation and the propName variable provided, console.log() the value of the 'Active Mission' property.

and the result is the following:

let spaceship = {
  'Fuel Type' : 'Turbo Fuel',
  'Active Mission' : true,
  homePlanet : 'Earth', 
  numCrew: 5
 };

let propName =  'Active Mission';

// Write your code below
let isActive = spaceship['Active Mission'];
console.log(propName);

Why do they provided the variable ‘propName’ to include in the code? if I use this variable to access the Active Mission property, the only thing I will get is a string.

Link to Exercise: Bracket Notation

Using bracket notation and the propName variable provided, console.log() the value of the 'Active Mission' property.

// You wrote:
console.log(propName);

// It should be:
console.log(spaceship[propName]);
1 Like