It says lookup is not defined

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
  return result;
}

// Change this value to test
result = lookup[val];

Your browser information:

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

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

Hi @amypolito,

The lookup is not defined because you declared it inside the function and you can’t access it outside, this is a “scope” problem.

In this case, you would want to assign the result to lookup[val] (result=lookup[val]) right before you return the result and keep the code under comment //Change this value to test unchanged.

Hope this helps!

perfect! thank you! i didn’t realize it was a scope problem