Another Quickie

Tell us what’s happening:
What is the point of the line var result = “”;?

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

phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0.

Challenge: Using Objects for Lookups

Link to the challenge:

Hi, you do not need it in that case.

Instead remove ist and try only:
let result = lookup[value];

at line 14.

It’s also a code style thing.

Some think declaring all variables at the top of the code block helps with legibility, some say the declaration should be as close to the variables usage as possible. Both can be valid points.

Some think declaring the variable and giving it the expected type, i.e. in this case a string, will help with the value assignment later. It’s like a form of type annotation.