Using Objects for Lookups - with dot notation

Hello!

I just finished the “Using Objects for Lookups” exercise, and I was stuck at it for a moment due to a very small mistake. Even if I managed to pass it, I still can’t figure out what was wrong with my last code. I feel like it should have been right, according to what I learned in the previous exercises.

This is the code that would not let me pass:

// 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("foxtrot");


When I changed
result = lookup.val;

to

result = lookup[val];

So now I’m wondering why I can only use bracket notation in this case and not dot notation.

1 Like
1 Like

Alright, that makes perfect sense.

Thanks for a very fast reply! Much appreciated.