freeCodeCamp Challenge Guide: Accessing Object Properties with Bracket Notation

Accessing Object Properties with Bracket Notation


Solutions

Solution 1 (Click to Show/Hide)
const testObj = {
  "an entree": "hamburger",
  "my side": "veggies",
  "the drink": "water"
};

// Only change code below this line

const entreeValue = testObj["an entree"]; // Change this line
const drinkValue = testObj["the drink"]; // Change this line
12 Likes

finally figured it out:

// Setup
var testObj = {
“an entree”: “hamburger”,
“my side”: “veggies”,
“the drink”: “water”
};

// Only change code below this line

var entreeValue = testObj[“an entree”]; // Change this line
var drinkValue = testObj[“the drink”]; // Change this line

9 Likes