Accessing Objects Properties with Bracket Notation

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

// Only change code below this line

var entreeValue = testObj; // Change this line
var drinkValue = testObj; // Change this line

This what they want me to do:
1)entreeValue should be a string
2)The value of entreeValue should be "hamburger"
drinkValue should be a string
3)The value of drinkValue should be "water"
4)You should use bracket notation twice

This is how i answered it but its wrong.
This my code code
// Setup
var testObj = {
“an entree”: “hamburger”,
“my side”: “veggies”,
“the drink”: “water”
};

// Only change code below this line

var entreeValue = testObj[“humnurger”]; // Change this line
var drinkValue = testObj [‘Water’]; // Change this line

The problem wants you to retrieve the values 'hamburger' and 'water' from the testObj object and assign them to the variables entreeValue and drinkValue, respectively.

Note that testObj has three keys: 'an entree', 'my side', and 'the drink'. Now which of these should you use to retrieve 'hamburger' and 'water'? Pick those two keys that go in between the brackets.

This is what i have tried

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

// Only change code below this line

testObj[“an entree”]; // Change this line
testObj [‘the drink’]; // Change this line
It failed perhaps what is required o me

With the new code, did you assign them back to the entreeValue and drinkValue variables?

yes i assingn them back

Hmm…I passed it with the following code:

`// 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"]; `
1 Like

Thank you so much at first i coded it exactly like yours but i got it wrong probably it had to do with spacing