&&
) returns true
if and only if the operands to the left and right of it are true.
The same effect could be achieved by nesting an if statement inside another if:
if (num > 5) {will only return "Yes" if
if (num < 10) {
return "Yes";
}
}
return "No";
num
is greater than 5
and less than 10
. The same logic can be written as:
if (num > 5 && num < 10) {
return "Yes";
}
return "No";
"Yes"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, will return "No"
.
&&
operator once
testString: 'assert(code.match(/&&/g).length === 1, ''You should use the &&
operator once'');'
- text: You should only have one if
statement
testString: 'assert(code.match(/if/g).length === 1, ''You should only have one if
statement'');'
- text: testLogicalAnd(0)
should return "No"
testString: 'assert(testLogicalAnd(0) === "No", ''testLogicalAnd(0)
should return "No"'');'
- text: testLogicalAnd(24)
should return "No"
testString: 'assert(testLogicalAnd(24) === "No", ''testLogicalAnd(24)
should return "No"'');'
- text: testLogicalAnd(25)
should return "Yes"
testString: 'assert(testLogicalAnd(25) === "Yes", ''testLogicalAnd(25)
should return "Yes"'');'
- text: testLogicalAnd(30)
should return "Yes"
testString: 'assert(testLogicalAnd(30) === "Yes", ''testLogicalAnd(30)
should return "Yes"'');'
- text: testLogicalAnd(50)
should return "Yes"
testString: 'assert(testLogicalAnd(50) === "Yes", ''testLogicalAnd(50)
should return "Yes"'');'
- text: testLogicalAnd(51)
should return "No"
testString: 'assert(testLogicalAnd(51) === "No", ''testLogicalAnd(51)
should return "No"'');'
- text: testLogicalAnd(75)
should return "No"
testString: 'assert(testLogicalAnd(75) === "No", ''testLogicalAnd(75)
should return "No"'');'
- text: testLogicalAnd(80)
should return "No"
testString: 'assert(testLogicalAnd(80) === "No", ''testLogicalAnd(80)
should return "No"'');'
```