Using Objects for Lookups - Not returning undefined -?

Hi - test is not passing for undefined case. Can’t figure out reason :(. Thx

Tell us what’s happening:

// running tests

phoneticLookup("") should equal undefined

// tests completed

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

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

Hi @brettstark73,

Remove the last key-value pair in the lookup object i.e., "" : "undefined"

When we try to access non-existing property in an object, it returns undefined. Hence we don’t have to explicitly write "" : "undefined" property in the lookup object.

1 Like

Thanks. mutter / mumble.

1 Like

An other thing is, you have used the string "undefined" but instead what it needs to be returnining is the keyword undefined, which is a reserved keyword with specific meaning
See, even different color:

undefined         // you want this 
"undefined"      // not this 
1 Like