If you have tabular data[表格数据], you can use an object to "lookup" values rather than a switch
statement or an if/else
chain.
当使用表格数据时用对象进行查找value
要求:Convert the switch statement into an object called lookup
. Use it to look up val
and assign the associated string to the result
variable.
function phoneticLookup(val) {
var lookup = {
alpha:"Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo:"Easy",
foxtrot:"Frank"
}
var result=lookup[val];
return result;
}
//test
console.log(phoneticLookup("charlie"));
val];
return result;
}
//test
console.log(phoneticLookup("charlie"));