Basic JavaScript - Using Objects for Lookups

Tell us what’s happening:

Describe your issue in detail here.
Can anybody help me find the bug in this code.
// Setup
function phoneticLookup(val) {
let result = “”;

// Only change code below this line
switch(val) {
“alpha”: “Adams”,
“bravo”: “Boston”,
“charlie”: “Chicago”,
“delta”: “Denver”,
“echo”: “Easy”,
“foxtrot”: “Frank”
}
result = lookup[val]
console.log(result)

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

phoneticLookup(“charlie”);

Your code so far

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

  // Only change code below this line
  switch(val) {
   "alpha": "Adams",
   "bravo": "Boston",
   "charlie": "Chicago",
   "delta": "Denver",
   "echo": "Easy",
   "foxtrot": "Frank"
   }
   result = lookup[val]
   console.log(result) 

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

Challenge Information:

Basic JavaScript - Using Objects for Lookups

Hello @adnan1 !

For this lesson we are not supposed to use the switch function.

Convert the switch statement into an object called lookup. Use it to look up val and assign the associated string to the result variable.

So we are to use lookup and the result is variable. How would we get a variable result?

I hope this helps you. You should only need to change the switch and val out for success, I believe. The rest looks good to me.

1 Like

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