Repository navigation
#017 Using the AND Operator
Consider a && b:
a is checked if it is true or false.
If a is false, false is returned.
b is checked if it is true or false.
If b is false, false is returned.
Otherwise, true is returned (as both a and b are therefore true ).
Rembember that the default value for bool is false. (eg. var c = new bool(); c is false.)
The && operator will only return true for true && true.
Make a function using the && operator.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/017 Using the AND Operator.js"Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.
This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.
//Consider a && b:
//a is checked if it is true or false.
//If a is false, false is returned.
//b is checked if it is true or false.
//If b is false, false is returned.
//Otherwise, true is returned (as both a and b are therefore true ).
//Rembember that the default value for bool is false. (eg. var c = new bool(); c is false.)
//The && operator will only return true for true && true.
//Make a function using the && operator.
function and(a, b) {
return a && b;
}
import * as Test from '../testHelper.js';
Test.assertEquals(and(true, true), true)
Test.assertEquals(and(true, false), false)
Test.assertEquals(and(false, true), false)
Test.assertEquals(and(false, false), false)