Using Objects for Lookups help pls

Tell us what’s happening:
please help me out with my code, how will i get phonetic("") to be undefined.i have been stucked here for hours.

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



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

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

Your browser information:

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

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

At the beginning of your code, you can just simply check if val equals empty string then return undefined.

ok i will try that right away

thanks phil but that didnt work

I see what’s wrong.

You aren’t supposed to use any if statements here. In that case, you can remove an unnecessary variable here.

Fix this to

result = lookup[val]

The previous code stringifies undefined to a string that’s why it was failing.

Don’t initialize result to an empty string and then concattenate it. That is turning the undefined that you get when you attempt to look up "" into the string "undefined".

wow, thanks so much,it worked. i am relieved, thanks phill.

thanks so much,it worked. thanks Leslie.