Basic JavaScript - Using Objects for Lookups

Tell us what’s happening:
Describe your issue in detail here.my issue has been answered but not quite to my understanding. Previously it was explained was needed with an example which if any of the object properties had not been numeric then in fact dot notation would have been okay. Why is this code not global inside the function or whatever it is that makes the val have to be enclosed in square brackets? please. thanks.

Your code so far

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

  // Only change code below this line
  
let lookup = {
    "alpha":  "Adams",      
    "bravo":  "Boston",
    "charlie":  "Chicago",
    "delta": "Denver",
    "echo":  "Easy",
    "foxtrot": "Frank",
val: 'result'
};
result= lookup[val];
//wanted as well result= lookup.val;
  // 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 OPR/96.0.0.0

Challenge: Basic JavaScript - Using Objects for Lookups

Link to the challenge:

Dot notation only works for the exact literal name of the property. It won’t work with a variable holding the property name.

1 Like

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