Can't solve Using Objects for Lookups

I cannot figure this one out. I’ve copied the formatting in the example but it is still wrong. I have no idea what I need to do to solve this even after checking the forums.

Help really appreciated.

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

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

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

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0

Challenge: Using Objects for Lookups

Link to the challenge:

Okay I solved it, but can someone explain why this works? Because I have no clue how this makes my code pass or what it is doing.

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

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

phoneticLookup("charlie");

Hi @ EllaGriff

I guess the first thing I’d like to ask, is whether or not you feel that you understood what this challenge was asking you to do.
Not in coding terms - just whether you understood in “real-life” terms what the challenge was asking for.
If that makes sense(!).

1 Like

You can play with the code and console log the function call.

Your function has the parameter val and whatever argument is passed on your function, you are looking up keys (value of val is the key in this case) of the lookup object.

Remember bracket notation?

1 Like