3.2 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244d8 Comparisons with the Logical And Operator 1 与逻辑和运算符的比较

Description

有时你需要一次测试多个东西。当且仅当其左侧和右侧的操作数true时, 逻辑和运算符( && 才返回true。如果将if语句嵌套在另一个语句中则可以实现相同的效果
ifnum> 5{
ifnum <10{
返回“是”;
}
}
返回“否”;
如果num大于5且小于10则仅返回“Yes”。相同的逻辑可以写成
ifnum> 5 && num <10{
返回“是”;
}
返回“否”;

Instructions

将两个if语句合并为一个语句如果val小于或等于50且大于或等于25 ,则返回"Yes" 。否则,将返回"No"

Tests

tests:
  - text: 你应该使用一次<code>&amp;&amp;</code>运算符
    testString: 'assert(code.match(/&&/g).length === 1, "You should use the <code>&&</code> operator once");'
  - text: 你应该只有一个<code>if</code>语句
    testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
  - text: <code>testLogicalAnd(0)</code>应返回“否”
    testString: 'assert(testLogicalAnd(0) === "No", "<code>testLogicalAnd(0)</code> should return "No"");'
  - text: <code>testLogicalAnd(24)</code>应返回“否”
    testString: 'assert(testLogicalAnd(24) === "No", "<code>testLogicalAnd(24)</code> should return "No"");'
  - text: <code>testLogicalAnd(25)</code>应返回“是”
    testString: 'assert(testLogicalAnd(25) === "Yes", "<code>testLogicalAnd(25)</code> should return "Yes"");'
  - text: <code>testLogicalAnd(30)</code>应该返回“是”
    testString: 'assert(testLogicalAnd(30) === "Yes", "<code>testLogicalAnd(30)</code> should return "Yes"");'
  - text: <code>testLogicalAnd(50)</code>应该返回“是”
    testString: 'assert(testLogicalAnd(50) === "Yes", "<code>testLogicalAnd(50)</code> should return "Yes"");'
  - text: <code>testLogicalAnd(51)</code>应返回“否”
    testString: 'assert(testLogicalAnd(51) === "No", "<code>testLogicalAnd(51)</code> should return "No"");'
  - text: <code>testLogicalAnd(75)</code>应返回“否”
    testString: 'assert(testLogicalAnd(75) === "No", "<code>testLogicalAnd(75)</code> should return "No"");'
  - text: <code>testLogicalAnd(80)</code>应返回“否”
    testString: 'assert(testLogicalAnd(80) === "No", "<code>testLogicalAnd(80)</code> should return "No"");'

Challenge Seed

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

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

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

// Change this value to test
testLogicalAnd(10);

Solution

// solution required