Basic JavaScript - Using Objects for Lookups

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

Your code so far

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

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

  // Only change code above this line
  return result;


Your browser information:

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

Challenge: Basic JavaScript - Using Objects for Lookups

Link to the challenge:

:balloon: Hi, welcome to the forum!
We see you have posted some code but did you have a question?

why cant we use result = Lookup.val here in 14th line instead of result = Lookup[val] ?

Those would be two different things. The first case would be getting the value of the property named “val”. The second is getting the property whose name matches the string in the variable val.

Because the Lookup object does not have a key named val.
If the object’s key value is only known at runtime, then we need to use bracket notation.

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