Tell us what’s happening:
Hello everyone! I noticed that var lookup is greyed out, and it seems to not be “declared”. Soi was seeing if someone can help me figure out why it says that, and how i can fix it. Thanks!
**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"
};
phoneticLookup["charlie"];
result = phoneticLookup;
// 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/94.0.4606.71 Safari/537.36 Edg/94.0.992.38
Thanks for responding! Interesting, this is what i have so far. And i think I see what you mean with "charlie"
however when i tried to assign the corresponding string to result, i might be messing up somewhere because i don’t think it’s working.
// 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"
};
lookup["charlie"];
result = "Chicago";
// Only change code above this line
return result;
}
phoneticLookup("charlie");
Your function is literally just returning the string “Chicago”, it is functionally identical to doing this.
function phoneticLookup() {
return "Chicago";
}
You are hardcoding the key value for the lookup. You should be using the function parameter val as the key value. Then return the value the lookup evaluates to.
function getLastName(firstName) {
const lookup = {
'John': 'Doe'
}
return lookup[firstName]
}
console.log(getLastName('John')); // Doe
In the case of this challenge, the test expects to find return result; in the code so you can’t just return the lookup value as in the example above.