Using Objects for Lookups help pls

Using Objects for Lookups help pls
0

#1

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


#2

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


#3

ok i will try that right away


#4

thanks phil but that didnt work


#5

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.


#6

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".


#7

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


#8

thanks so much,it worked. thanks Leslie.