Using Objects for Lookups: can’t do it

I’m trying to go back to earlier lessons to do the record collection lesson eventually.

But I can’t solve this one. I just can’t work it out what I’m missing and not doing.

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

// Only change code below this line
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 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15

Challenge: Using Objects for Lookups

Link to the challenge:

what’s the value of result? considering this is what the function returns, you need to make sure that resulthas the rigth value

you are also missing the keyword to declare a variable here

I’ve declared the variable now. Sorry I’ve been trying to code almost all afternoon and I’m forgetting things.

The value is an empty string but I don’t know what to do with it. I can’t make it be the right thing.

// Setup
function phoneticLookup(val) {
let 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
result = lookup;
return result;
}

phoneticLookup("charlie");

ok, here you have made the variable result not an empty string.

But, what should your function do?
Given an input it should give back an output, right?
what are these inputs and outputs?

You’re returning the entire object instead of a particular key. result should be followed by something

The input is the values in lookup. I don’t know what the output is.

The challenge description asks you to return something
You need to know what is the required output before coding

Like, there is written this:

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

You did the first sentence, you are missing the second one

I don’t know how to assign the string. I can’t see a way to do it. I think I’m too tired to understand what I’m doing.

I am sorry for wasting time.

try reading again the description, it shows how to get values out of an alphabet lookup

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