Basic JavaScript - Using Objects for Lookups

```

result = lookup.val; or result = lookup[val];

Why does dot not work instead of bracket

### Your code so far


```javascript
// 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;
// why does this work with bracket not with dot


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

phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0

Challenge Information:

Basic JavaScript - Using Objects for Lookups

you’re dynamically accessing the property of the lookup object
using a variable (val ), and the dot notation doesn’t allow for dynamic property access.

2 Likes

Thanks for the reply and should i just use brackets

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