Why is return return result; necessary?

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",
};
return lookup [val];
// Only change code above this line
return result; **why is this line necessary? considering return lookup[val]; is above**
}

phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Using Objects for Lookups

Link to the challenge:

It looks like the assumption is that you’ll reassign the result variable.

Thanks for your reply :slight_smile: I was under the impression the code would stop after the first return lookup [val];

It does stop after the first return statement. What I meant to say is that, based on how the starter code is written, taking into account that they declare and return the result variable for you, the assumption is that you won’t write a return statement between the // Only change code... comments.

In code, the person who wrote this challenge expected you to write

result = lookup[val];

instead of

return lookup[val];

It’s all the same in the end, however.

1 Like

that clarifies it - TYVM :pray: