Basic JavaScript - make switch statement into an object

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

Your code so far
my code is let lookUp={} //the object
Hi, …
why cannot the answer by result= lookUp.val instead of lookUp[val]

// 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"
result = lookUp[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 Edg/108.0.1462.46

Challenge: Basic JavaScript - Using Objects for Lookups

Link to the challenge:

Because using dot notation is not dynamic. It looks up the value of the property literally named “val” on your object, which does not exist. Refer back to the introductory lessons on objects where it explains the difference.

I thought it was taught that single word properties could be used without quotation marks and thus without square brackets.

What the property is called has nothing to do with weather or not the property name is stored in a variable.

ah, like iteration. val is temporary.

Not really the core issue here. val is a variable. Bracket notation is mandatory with variables holding the property name.

This says look into the variable val to find the name of the property:


This says that “val” is the name of the property:

1 Like

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