Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
587d7b7e367417b2b2512b24 使用三元运算符 1 https://scrimba.com/c/c3JRmSg 301181 use-the-conditional-ternary-operator

--description--

条件运算符(也称为三元运算符)的用处就像写成一行的 if-else 表达式

语法如下所示:

condition ? statement-if-true : statement-if-false;

以下函数使用 if-else 语句来检查条件:

function findGreater(a, b) {
  if(a > b) {
    return "a is greater";
  }
  else {
    return "b is greater";
  }
}

上面的函数使用条件运算符写法如下:

function findGreater(a, b) {
  return a > b ? "a is greater" : "b is greater";
}

--instructions--

checkEqual函数中使用条件运算符检查两个数字是否相等,函数应该返回 "Equal" 或 "Not Equal"

--hints--

checkEqual应该使用条件运算符。

assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?/.test(code));

checkEqual(1, 2)应该返回 "Not Equal"。

assert(checkEqual(1, 2) === 'Not Equal');

checkEqual(1, 1)应该返回 "Equal"。

assert(checkEqual(1, 1) === 'Equal');

checkEqual(1, -1)应该返回 "Not Equal"。

assert(checkEqual(1, -1) === 'Not Equal');

--seed--

--seed-contents--

function checkEqual(a, b) {

}

checkEqual(1, 2);

--solutions--

function checkEqual(a, b) {
  return a === b ? "Equal" : "Not Equal";
}