Here is the code I was doing:
// Setup
function phoneticLookup(val) {
var result = “”;
// Only change code below this line
var phoneticLookup ={
alpha:“Adams”,
bravo: "Boston",
charlie: "Chicago",
delta: “Denver”,
echo: "Easy",
foxtrot: "Frank",
};
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup(“charlie”);
When I hit the run test button it keeps saying that
phoneticLookup(“alpha”) should equal "Adams"
phoneticLookup(“bravo”) should equal "Boston"
phoneticLookup(“charlie”) should equal "Chicago"
phoneticLookup(“delta”) should equal "Denver"
phoneticLookup(“echo”) should equal “Easy"
phoneticLookup(“foxtrot”) should equal “Frank"
phoneticLookup(””) should equal undefined
I don’t understand what else I should do? IT all looks equal to me. What is the problem? Any help is appreciated.
You’re doing great so far! Just a few small items to consider:
Change the value of the variable result. Currently, result is always returning an empty string.
Change the name of your object from phoneticLookup to lookup. This might make it more clear that the tests being run are calling the function phoneticLookup and not the object.
The last key:value pair in your object should not have a trailing comma.
I tried to follow 0x0936 's considerations… here is what I did:
`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;
}
// Change this value to test
phoneticLookup(“charlie”);`
dot notation did NOT work in this exercise. Not sure why… What did work is the following:
[spoiler]
// 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;
}
// Change this value to test
phoneticLookup(“charlie”);[/spoiler]
You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
We have set your post to unlisted. Thanks for your understanding.