Lookups code error

Lookups code error
0

#1

Tell us what’s happening:

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",
  };
  result = lookup.val;
   

  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:


#2

You did not specify a question, but I assume you are wondering why result does not get assigned a value from the lookup object. When you write:

lookup.val

you are using dot notation, so you are assuming there is an actual property in the lookup object called “val”. There is not, so it returns undefined. Since val is actually a variable, you need to use bracket notation. See if you can solve the challenge now.


#3

Hi @RandellDawson

Yes. I just wanted to know why was not working. I actually tried after with the bracket notation and worked but i didn’t understand why but now i do.
Thank you for your help.