Using Objects for Lookups - Pointers appreciated

Currently my code below is outputting:

Cannot read property ‘charlie’ of undefined

I have no idea where the fault lies and would really appreciate some pointers on where the issue is.

Thanks in advance :slight_smile:

// Setup
function phoneticLookup(val) {
  var result = lookup[val];

  // 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
phoneticLookup("charlie");

Managed to figure it out lol. Happy coding! :blush:

For other people looking at this thread, the error was var result = lookup[val] was called before the lookup object was set.

The correct code is below;

function phoneticLookup(val) {
  // Only change code below this line

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

  var result = lookup[val];

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