Question about Using Objects for Lookups

Question about Using Objects for Lookups
0

#1

Hi everybody,

I have a question about the “Using Objects for Lookups” challenge, even though I found the solution I was wondering about the fact that we have to remove the var keyword from the result variable even though it is inside a function which result in a global variable inside a function which is not so good as you can see in my code bellow

// Setup
function phoneticLookup(val) {
  var lookup = {
  "alpha": "Adams",
  "bravo": "Boston",
  "charlie": "Chicago",
  "delta": "Denver",
  "echo": "Easy",
  "foxtrot": "Frank"
  };
  
  result = lookup[val];

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

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

I would like to know why we have to remove the var keyword for it to pass the test

Thanks


#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

Thanks for the advice !!