Accessing Objects Properties with Bracket Notation

Accessing Objects Properties with Bracket Notation
0

#1

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


#2

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.


#3

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


#4

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


#5

yes i assingn them back


#6

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

#7

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