I am not sure I understand why the code below works.
In particular, how does the function know what value to pass through the lookup list (alpha, charlie, bravo…)? Where is it stated that val = parameter?
Very confused…
// 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;
}
// Change this value to test
phoneticLookup("charlie");
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.