I’ve been trying to pass the test for 20 days I feel like giving up

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

  **Your code so far**

// 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";
}
var result = "";
// Only change code above this line
return result;
}

phoneticLookup("charlie");
  **Your browser information:**

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Mobile/15E148 Safari/604.1

Challenge: Using Objects for Lookups

Link to the challenge:

The instructions say:

“Convert the switch statement into an object called lookup .”

I don’t see any evidence in the code you’ve posted that you’ve attempted to do that. If you have then please post that code instead.

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

   **Your code so far**

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

 // Only change code below this line
 var result ="";
 var lookup = {
"alpha": "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"

 };
result = lookup[val];
/* 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 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Mobile/15E148 Safari/604.1

Challenge: Using Objects for Lookups

Link to the challenge:

Could you write what’s the problem?

You can not re-declare result after it has been declared using let

Look at the output:

// SyntaxError: unknown: Identifier 'result' has already been declared. (6:5)

When I remove var result =""; your code passes.

1 Like

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