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

2.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d8 逻辑与运算符 1 https://scrimba.com/c/cvbRVtr 16799 comparisons-with-the-logical-and-operator

--description--

有时你需要在一次判断中做多个操作。当且仅当运算符的左边和右边都是true逻辑与 运算符(&&)才会返回true

同样的效果可以通过 if 语句的嵌套来实现:

if (num > 5) {
  if (num < 10) {
    return "Yes";
  }
}
return "No";

只有当num的值在 6 和 9 之间(包括 6 和 9才会返回 "Yes"。相同的逻辑可被写为:

if (num > 5 && num < 10) {
  return "Yes";
}
return "No";

--instructions--

请使用逻辑与运算符把两个 if 语句合并为一个 if 语句,如果val小于或等于50并且大于或等于25,返回"Yes"。否则,将返回"No"

--hints--

你应该使用&&运算符一次。

assert(code.match(/&&/g).length === 1);

你应该只有一个if表达式。

assert(code.match(/if/g).length === 1);

testLogicalAnd(0)应该返回 "No"。

assert(testLogicalAnd(0) === 'No');

testLogicalAnd(24)应该返回 "No"。

assert(testLogicalAnd(24) === 'No');

testLogicalAnd(25)应该返回 "Yes"。

assert(testLogicalAnd(25) === 'Yes');

testLogicalAnd(30)应该返回 "Yes"。

assert(testLogicalAnd(30) === 'Yes');

testLogicalAnd(50)应该返回 "Yes"。

assert(testLogicalAnd(50) === 'Yes');

testLogicalAnd(51)应该返回 "No"。

assert(testLogicalAnd(51) === 'No');

testLogicalAnd(75)应该返回 "No"。

assert(testLogicalAnd(75) === 'No');

testLogicalAnd(80)应该返回 "No"。

assert(testLogicalAnd(80) === 'No');

--seed--

--seed-contents--

function testLogicalAnd(val) {
  // Only change code below this line

  if (val) {
    if (val) {
      return "Yes";
    }
  }

  // Only change code above this line
  return "No";
}

testLogicalAnd(10);

--solutions--

function testLogicalAnd(val) {
  if (val >= 25 && val <= 50) {
    return "Yes";
  }
  return "No";
}