My code works but when I do result= lookup.val; dot notation, it doesn’t work. I wonder why? As I know u can use dot or bracket notation to get value
Your code so far
// Setup
function phoneticLookup(val) {
let result = "";
// Only change code below this line
const 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
This one was very astonishing for me to learn. You see dot notation . only deals with static keys. That is keys aren’t programmatically assigned. Right now the lookup is trying to find a value called “val” in the object, that simply doesn’t exist.
Bracket notation however doesn’t have this problem. It can have literally any key during runtime.