Using Objects for Lookups - need urgent help

Tell us what’s happening:
so i am having difficulties with this code, i know i am missing something, just don’t know what it is.

Thanks.

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

// Change this value to test
phoneticLookup("charlie");

Your browser information:

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

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

You have the object correct, but you never assign a value to result. If you add a line of code at the end console.log(phoneticLookup("charlie")), you will get undefined. Try using the val that is passed to the function to look up the value in the object, then assign that to the result value you are returning.

eg.
In the directions it gives the example with the alpha object. If you wanted to return the second value from that object, you would want to have a line result = alpha[2]

I’m trying not to give you the answer directly if I can help it, it’s better to get a hint and figure it out yourself :slight_smile: . Let me know if this doesn’t make sense and I can give you a more detailed explanation.

1 Like

This was really helpful, i was able to assign lookup with the val attribute to result and it worked, thanks @lucassorenson :+1::+1::+1::+1: