Objects for lookups

Tell us what’s happening:
please someone should help me on this
i am stuck

Your code so far


// 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;
}

phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Using Objects for Lookups

Link to the challenge:

First, you’ll have to remove this line, because it’ll break your code.

   "" :

Then take a closer look how your function work. At the beginning you create a variable:

var result = "";

And at the end you return it.

return result;

But in between nothing is happening to this variable, so every time you call this function it will return an empty string.

For the function call:

phoneticLookup("charlie")

The function parameter val will contain the string “charlie”. Now you can use the parameter (which is just a variable) to do a lookup on the object lookup[val]. Remember to return the value.


Example without a function (the variable userName is like the val parameter).

const user = {
  charlie: 'Sheen'
}

const userName = 'charlie';

user[userName] // 'Sheen'