Please guys what is wrong with my codes: Using Objects for Lookups

Please guys what is wrong with my codes: Using Objects for Lookups
0

#1

Tell us what’s happening:

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; 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

Looks perfect except you don’t need to put the keys in quotation marks :blush:
You also want to return result at the end, however you could just use

return lookup.val


#3

There a some improvements:

  • The last item in the lookup ends with a comma, you can remove it.
  • Nothing is being returned in the function. You need to have somewhere return result;.
  • There is a comma between lookup and [val]; Why?
  • You should not change the code after the comment // Only change code above this line

#4

am still having the issue, after removing quotation mark:

 var lookup = {
    alpha: "Adams",
    bravo:  "Boston",
    charlie: "Chicago",
    delta:  "Denver",
    echo:  "Easy",
    foxtrot:  "Frank"
  };

#5

Have you got the return statement in there?

return lookup.val


#6

thanks a lot I has pass the test. I miss out on the return statement. Thank you for your time.


#7

In the future a “linter” can help you catch simple mistakes like some of the ones you made above:

https://jshint.com/

You can also install these linters in your editor, very handy.


#8

wow, I’ll check it out, thanks I really appreciate.