Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* 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
2020-03-03 18:49:47 +05:30

2.5 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244de Adding a Default Option in Switch Statements 1 在交换机语句中添加默认选项

Description

switch语句中,您可能无法将所有可能的值指定为case语句。相反,您可以添加default语句,如果找不到匹配的case语句,将执行该语句。可以把它想象成if/else链中的最后一个else语句。 default语句应该是最后一种情况。
switchnum{
案例值1
语句1;
打破;
案例值2
语句2;
打破;
...
默认:
defaultStatement;
打破;
}

Instructions

写一个switch语句来设置以下条件的answer
"a" - “苹果”
"b" - “鸟”
"c" - “猫”
default - “东西”

Tests

tests:
  - text: <code>switchOfStuff(&quot;a&quot;)</code>的值应为“apple”
    testString: assert(switchOfStuff("a") === "apple");
  - text: <code>switchOfStuff(&quot;b&quot;)</code>的值应为“bird”
    testString: assert(switchOfStuff("b") === "bird");
  - text: <code>switchOfStuff(&quot;c&quot;)</code>的值应为“cat”
    testString: assert(switchOfStuff("c") === "cat");
  - text: <code>switchOfStuff(&quot;d&quot;)</code>的值应为“stuff”
    testString: assert(switchOfStuff("d") === "stuff");
  - text: <code>switchOfStuff(4)</code>的值应为“stuff”
    testString: assert(switchOfStuff(4) === "stuff");
  - text: 您不应该使用任何<code>if</code>或<code>else</code>语句
    testString: assert(!/else/g.test(code) || !/if/g.test(code));
  - text: 您应该使用<code>default</code>语句
    testString: assert(switchOfStuff("string-to-trigger-default-case") === "stuff");
  - text: 你应该至少有3个<code>break</code>语句
    testString: assert(code.match(/break/g).length > 2);

Challenge Seed

function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line



  // Only change code above this line
  return answer;
}

// Change this value to test
switchOfStuff(1);

Solution

// solution required