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.8 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244e0 Replacing If Else Chains with Switch 1 如果用交换机替换其他链条

Description

如果您有许多选项可供选择,那么switch语句比许多链接的if / else if语句更容易编写。下列:
ifval === 1{
answer =“a”;
} else ifval === 2{
answer =“b”;
} else {
answer =“c”;
}
可以替换为:
switchval{
情况1
answer =“a”;
打破;
案例2
answer =“b”;
打破;
默认:
answer =“c”;
}

Instructions

将链接的if / else if语句更改为switch语句。

Tests

tests:
  - text: 您不应该在编辑器中的任何位置使用任何<code>else</code>语句
    testString: assert(!/else/g.test(code));
  - text: 您不应在编辑器中的任何位置使用任何<code>if</code>语句
    testString: assert(!/if/g.test(code));
  - text: 你应该至少有四个<code>break</code>语句
    testString: assert(code.match(/break/g).length >= 4);
  - text: <code>chainToSwitch(&quot;bob&quot;)</code>应该是“Marley”
    testString: assert(chainToSwitch("bob") === "Marley");
  - text: <code>chainToSwitch(42)</code>应该是“答案”
    testString: assert(chainToSwitch(42) === "The Answer");
  - text: <code>chainToSwitch(1)</code>应该是“没有1”
    testString: "assert(chainToSwitch(1) === \"There is no #1\");"
  - text: <code>chainToSwitch(99)</code>应该是“错过了我这么多!”
    testString: assert(chainToSwitch(99) === "Missed me by this much!");
  - text: <code>chainToSwitch(7)</code>应该是“Ate Nine”
    testString: assert(chainToSwitch(7) === "Ate Nine");
  - text: <code>chainToSwitch(&quot;John&quot;)</code>应为“”(空字符串)
    testString: assert(chainToSwitch("John") === "");
  - text: <code>chainToSwitch(156)</code>应为“”(空字符串)
    testString: assert(chainToSwitch(156) === "");

Challenge Seed

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

  if (val === "bob") {
    answer = "Marley";
  } else if (val === 42) {
    answer = "The Answer";
  } else if (val === 1) {
    answer = "There is no #1";
  } else if (val === 99) {
    answer = "Missed me by this much!";
  } else if (val === 7) {
    answer = "Ate Nine";
  }

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

// Change this value to test
chainToSwitch(7);

Solution

// solution required