Use it to look up val and assign the associated string to the result variable.....um?

As the module’s go on, I find myself being increasingly more fustrated with JavaScript (I don’t expect to know everything of course). I totally understand the example they give but I am a little confused as to what they want me to do…actually I do understand what they want me to do but I can’t seem to do it.
Can some please help to explain it??

Also, I would love a bit of advice. I’m quite confident in remembering a lot of JavaScript’s syntax and doing basic problem solving but as the modules go on, I’m becoming more and more lost. Should I stop from this point on and go back to the beginning or buy a book (I actually purchased Jon Ducket’s JavaScript Book). I don’t want to complete the challenges for the sake of it if that makes sense.
Thanks guys

  **Your code so far**

// Setup
function phoneticLookup(val) {
var 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";
    break;

}*/
var lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo" : "Easy",
"foxtrot": "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/92.0.4515.159 Safari/537.36

Challenge: Using Objects for Lookups

Link to the challenge:

That is completely normal. It starts out easier and gets harder.

I’m quite confident in remembering a lot of JavaScript’s syntax and doing basic problem solving but as the modules go on, I’m becoming more and more lost.

Again, normal.

Should I stop from this point on and go back to the beginning or buy a book …

I would advise against it. I think you should keep pushing forward. If there is something that particularly confuses you, maybe jot it down on a notepad and when you get a little time, do a little research. See what it says on MDN, look for youtube videos, blog posts, etc. There is nothing that could possibly confuse you that hasn’t confused a lot of other people.

Can some please help to explain it??

So, looking at what you have…

First of all, get in the habit of formatting code as you go. Properly indented and formatted code is a lot easier to read. Taking the time to format properly will save you a lot of time in the long run.

So, you know that you won’t be using the switch statement, so, removing that, you are left with:

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

  // Only change code below this line

  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo" : "Easy",
    "foxtrot": "Frank",
  }

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

So, this looks good, a good start. The only thing that you are missing is where you use your lookup object and the key that is passed in as val to get the result and save it into result. I was able to get this to pass by adding one line.

So, use val as your key to get what you want out of that “dictionary”.

Does that make it easier? Let us know if you need more of a hint.

1 Like

Dude, thank you so much for taking time out to reply!
This is definitely a reply I will refer to as I continue on this journey; glad to hear that this type of ‘increased’ frustration is normal, I’ll keep going.

Yes, it hasn’t shown here but I have commented out the switch statements but didn’t delete just so I can remember the order.

I’m looking at your hint (many many thanks btw) a wee bit confused but I’m going to try it out now…I’m missing where I use my lookup object and the key that is passed…I’ll try it out now. Thanks for format advice as well!

Yeah, I saw that the switch was commented out.

I could give you an example to help you over the last step, but I fear it would be obvious. Give it a shot. Just remember how you get a specific key out of an object with bracket notation.

If you get stuck, check back and we’ll get you there.

Trust me, 71.8% of all professional developers readily admit that there are times of frustration that make them want to bang their heads on their desk. The other 28.2% are or course lying. The nature of learning and challenging is to frustrate you into growing. If you aren’t getting at least occasionally frustrated, you aren’t learning anything.

Great words that will stick in my head from now on!
Will try it alone and let you know how it goes! Maximum respect Kevin.

1 Like

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