* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
3.2 KiB
3.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244ca | Using Objects for Lookups | 1 | 使用对象进行查找 |
Description
switch
语句或if/else
链。当您知道输入数据限制在特定范围内时,这非常有用。以下是简单反向字母查找的示例: var alpha = {
1: “Z”,
2: “Y”,
3: “X”,
4: “W”,
...
24: “C”,
25: “B”,
26: “A”
};
阿尔法[2]; //“Y”
阿尔法[24]; // “C”
var value = 2;
阿尔法[值]。 //“Y”
Instructions
lookup
的对象。使用它来查找val
并将关联的字符串分配给result
变量。 Tests
tests:
- text: <code>phoneticLookup("alpha")</code>应该等于<code>"Adams"</code>
testString: assert(phoneticLookup("alpha") === 'Adams');
- text: <code>phoneticLookup("bravo")</code>应该等于<code>"Boston"</code>
testString: assert(phoneticLookup("bravo") === 'Boston');
- text: <code>phoneticLookup("charlie")</code>应该等于<code>"Chicago"</code>
testString: assert(phoneticLookup("charlie") === 'Chicago');
- text: <code>phoneticLookup("delta")</code>应该等于<code>"Denver"</code>
testString: assert(phoneticLookup("delta") === 'Denver');
- text: <code>phoneticLookup("echo")</code>应该等于<code>"Easy"</code>
testString: assert(phoneticLookup("echo") === 'Easy');
- text: <code>phoneticLookup("foxtrot")</code>应该等于<code>"Frank"</code>
testString: assert(phoneticLookup("foxtrot") === 'Frank');
- text: <code>phoneticLookup("")</code>应该等于<code>undefined</code>
testString: assert(typeof phoneticLookup("") === 'undefined');
- text: 您不应该修改<code>return</code>语句
testString: assert(code.match(/return\sresult;/));
- text: 您不应该使用<code>case</code> , <code>switch</code>或<code>if</code>语句
testString: assert(!/case|switch|if/g.test(code.replace(/([/]{2}.*)|([/][*][^/*]*[*][/])/g,'')));
Challenge Seed
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
switch(val) {
case "alpha":
result = "Adams";
break;
case "bravo":
result = "Boston";
break;
case "charlie":
result = "Chicago";
break;
case "delta":
result = "Denver";
break;
case "echo":
result = "Easy";
break;
case "foxtrot":
result = "Frank";
}
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
Solution
// solution required