Tell us what’s happening:
Describe your issue in detail here.
Your code so far
my code is let lookUp={} //the object
so…
Hi, …
why cannot the answer by result= lookUp.val instead of lookUp[val]
thanx
// Setup
function phoneticLookup(val) {
let result = "";
// Only change code below this line
let 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46
Challenge: Basic JavaScript - Using Objects for Lookups
Because using dot notation is not dynamic. It looks up the value of the property literally named “val” on your object, which does not exist. Refer back to the introductory lessons on objects where it explains the difference.