Using Objects for Lookups - help

Using Objects for Lookups - help
0.0 0

#1

Hey, I encountered a problem there is a simple exercise, but I’m not sure that my logic is correct.
anyone could me help ?

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"
  };
  var value = val;
  result += lookup[value];
  // Only change code above this line
  return result;
}

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

But still when I call function with empty string parameter. test shouts phoneticLookup("") should equal undefined


#2

Use = not +=, you’re trying to add undefined to a string, so your function will error rather than just returning undefined


#3

Yes it solved, I saw the previous topic with the same problem> Thanks a lot for your reply. :slight_smile: