Using Objects for Lookups - clarification

Tell us what’s happening:
Hi people, I just want to ask one thing, is it necessary to leave the variable result after the creation of the object? I mean the code works just fine callin the function so I don’t see why I don’t have to change the code below and above the line, am I missing something?

// Setup
function phoneticLookup(val) {
let result = ""; // <-this variable here

// Only change code below this line
var lookup = {
  "alpha": "Adams",
  "bravo": "Boston",
   "charlie":"Chicago",
   "delta":"Denver",
   "echo": "Easy",
   "foxtrot":"Frank"
};
return lookup[val];
// Only change code above this line
return result;
}

var test = phoneticLookup("charlie");
console.log(test);
  **Your browser information:**

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

Challenge: Using Objects for Lookups

Link to the challenge:

Yeah, what they wanted you to do was store that value in that variable and return it. You just returned it directly without storing it in a variable. That’s probably what I would have done in most cases. Maybe they were just trying to go more slowly so as not to confuse learners. But yeah, doing it the way you are doing, you don’t need to declare or return that variable.

I mean, technically there is a difference in how it handles it if that key isn’t found. That could be fixed with a short circuit OR (||), but it doesn’t test for that so it doesn’t matter in this case.

Why var? At this point in the curriculum you should not be using var.

1 Like

Ah good, that makes sense, I’ll just point that out in my notes, thank you!

Noted! I’ll pay more attention in the future!