Basic JavaScript - Using Objects for Lookups

I dont know what i have to do.

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

  // Only change code below this line
  switch(val) {
    case "alpha":
      result = "Adams";
      break;
    case "bravo":
      result = "Boston";
      break;
    case "charlie":
      result = "Chicago";
      break;
    case "delta":
      result = "Denver";
      break;
    case "echo":
      result = "Easy";
      break;
    case "foxtrot":
      result = "Frank";
  }

  // 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/115.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Using Objects for Lookups

Link to the challenge:

Take a look at the example in description. Goal is make object, similar to article, but based on the switch in the starting code.

1 Like

Instead of the code above, you should create an object with key-value pairs:

{
  "key": "value",
  "key": "value", etc.
}

Declare a variable and give it a proper name. Assign a newly created object to that variable. Then, assign that variable to the ‘result’ variable, with the ‘val’ argument put between brackets [].

After that, you will be able to print in the console the output:

console.log(phoneticLookup("echo")); ...for example

The output, for the example above, will be:
image

1 Like

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