Stuck at level 70 something (maybe 78)

Hello all,
I am stuck here and I have no idea what’s wrong. Can sbdy help me out and explain why this doesn’t work please? Thank you !

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

phoneticLookup("charlie");

what were you ask to do ?

In the future, if you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

use switch statement

switch(val){
case "alpha":
result="Adams"
break;
case "bravo" :
result = "Boston"
break;
case "charlie":
result ="Chicago"
break;
....
.....
....
default:
result="Not Found"
}

hope you understand?

1 Like

Thank you for your answer. Actually, what is asked remove a switch
" Convert the switch statement into an object called lookup . Use it to look up val and assign the associated string to the result variable."

This is the solution that is given when you click on “get a hint” :slight_smile:

function phoneticLookup(val) {
  var result = "";
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

I did click on “Ask for help” but I think that since I had to create the account, it didn’t redirect me there or I clicked somewhere I wasn’t supposed to ? Sorry

Link to challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups

Thank you @JeremyLT!!!

It looks like you are missing part of the code, as your function never closes with a }?

Anywho, in the code in your first post, you never change the variable result.

You aren’t doing anything with result. It is always an empty string. You need to use the lookup table in addition to creating it.

1 Like

bro you have really moltivated me to keep on learning

It says in the instructions that I shouldn’t modify the return statement

You don’t need to modify the return statement. But you need to modify the value stored in the variable that you are returning.

2 Likes

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