How is the..... (val ) or [val].... related to the properties in the object?

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; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Challenge: Using Objects for Lookups

Link to the challenge:

(val) is a parameter for the function phoneticLookup
[val] is used to access the properties of the Lookup object

so the function takes a parameter (val), in this case “charlie”, then result = Lookup[val] ie Lookup[“charlie”] which would be “Chicago”

If you do not understand my explanation, read this one which is detailed and will be helpful Using Objects for Lookups - Can you help explain what's going on?

1 Like