freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.chinese.md
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.3 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244dd Selecting from Many Options with Switch Statements 1 从带有开关语句的多个选项中进行选择

Description

如果您有很多选择,请使用 switch 语句。 switch 语句测试一个值,并且可以包含许多定义各种可能值的 case 语句。 从第一个匹配的 case 值开始执行语句,直到遇到 break 。 这是 switch 语句的示例:

switch(lowercaseLetter) {
  case "a":
    console.log("A");
    break;
  case "b":
    console.log("B");
    break;
}

case 值以严格相等性( === )进行测试。 break 告诉JavaScript停止执行语句。 如果省略 break ,将执行下一条语句。

Instructions

编写一个switch语句测试val并设置以下条件的answer
1 - “alpha”
2 - “beta”
3 - “伽玛”
4 - “三角洲”

Tests

tests:
  - text: <code>caseInSwitch(1)</code>的值应为“alpha”
    testString: assert(caseInSwitch(1) === "alpha");
  - text: <code>caseInSwitch(2)</code>的值应为“beta”
    testString: assert(caseInSwitch(2) === "beta");
  - text: <code>caseInSwitch(3)</code>的值应为“gamma”
    testString: assert(caseInSwitch(3) === "gamma");
  - text: <code>caseInSwitch(4)</code>的值应为“delta”
    testString: assert(caseInSwitch(4) === "delta");
  - text: 您不应该使用任何<code>if</code>或<code>else</code>语句
    testString: assert(!/else/g.test(code) || !/if/g.test(code));
  - text: 你应该至少有3个<code>break</code>语句
    testString: assert(code.match(/break/g).length > 2);

Challenge Seed

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



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

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

Solution

// solution required