I've done what i've been asked to do but still no head way

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

// Setup
function phoneticLookup(val) {
 var result = "";

 // Only change code below this line
var lookup = { 
  "alpha": "Adams",
   "bravo": "Boston",
   "charlie": "Chicago",
   "delta": "Denver",
   "echo": "Easy",
   "foxtrot": "frank"
};
 
 // Only change code above this line
 return result;

}
phoneticLookup("");
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 OPR/77.0.4054.172

Challenge: Using Objects for Lookups

Link to the challenge:

You have converted the switch to a lookup object but you aren’t returning the value in the lookup object associated with the val parameter passed into the function. You need to set result to the correct value before it returns.

Also, “frank” needs to be capitalized.

Perhaps another similar example may make it click.
you can think of the let’s use a restaurant menu as an example.
The value on the left of the colon (called the key in js) would be the item you ordered.
The value on the left of the colon (called the value in js) would be the item you ordered.

function orderFoodOffMenu(foodItemOrdered) {
 var price = "";

/ * KEY:VALUE */
/ * ITEM_ORDERD:PRICE */
var menu= { 
  "hamburger": "10.00",
  "hotDog": "5.00",
  "iceCream": "2.00"
};
 
 return price;
}
orderFoodOffMenu("hamburger");  //should return "10.00"
orderFoodOffMenu("iceCream");  //should return "2.00"

so you went ahead and added the menu but did not enter the item into the menu to get the price. To do this you would use bracket notation (covered a few lessons ago.

menu["hamburger"]  // goes to the menu look up hamburger and returns "10.00"
menu["iceCream"]  // goes to the menu look up iceCream and returns "2.00"

Now the tricky part is that on the level of the function we don’t know the foodItemOrdered. this prevents us from hardcoding it, but that’s okay because we can pass a variable into the menu the same way we do a string.

menu[foodItemOrdered]  // goes to the menu to lookup whatever the ordered food item is 

we can set the variable price to be equal to whatever that is

function orderFoodOffMenu(foodItemOrdered) {
 var price = "";

/ * KEY:VALUE */
/ * ITEM_ORDERD:PRICE */
var menu= { 
  "hamburger": "10.00",
  "hotDog": "5.00",
  "iceCream": "2.00"
};

price = menu[foodItemOrdered];

 return price;
}

Then elsewhere in code whenever we need to look up the price of a food item we can just call the function with the item we are ordering.

orderFoodOffMenu("hamburger");  //should return "10.00"
orderFoodOffMenu("iceCream");  //should return "2.00"

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.