Using Objects for Lookups - result problem

Your code so far

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"
  };
  result = lookup[val]

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

Tell us what’s happening:
I’m just wondering why

result = lookup[val]

I did everything in this challenge except that. Thought it may be the property statement but if it’s lookup.val it’s incorrent.

Challenge: Using Objects for Lookups

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

Frank with a capital F

1 Like

Ok, i’ve changed that. Then I changed result to result = lookup.val.
Now when i type in console.log(phoneticLookup(“charlie”)) it shows undefined

Ok i understand your problem now! Looks like it’s time for a refresher! You cannot use dot notation with variables, only bracket notation :slight_smile:

“Perhaps most importantly, we can now use variables to access properties in an object. It’s important the variable you are using references a String.”

2 Likes

Hey Bosch,
your coding looks fine and it matches my solution apart from capital F in frank that was pointed out, and a missing ; at the end of result = lookup[val].
I dont think you need the console.log() though.
phoneticLookup(“charlie”);
should do it, and just change “charlie” to “bravo” etc to test.

I only did this last night myself buddy so its a best guess.
Also I believe using the .val instead of [val] has to do with the properties being a variable instead of constant? I’ve seen this causing issues for other people on other parts of challenges.
try changing it back to
result = lookup[val];

exactly this! Clearer explanation than mine