1.Here is the assignment.
Declare a function or that works like ||, but without using the || operator. /**
- @param {any} ??? – the first operand
- @param {any} ??? – the second operand
- @returns {any} the same result as applying the || operator to the given operands, in order
2.Here is what tried(actually people gave me advice on return b1 ? b1 : b2.But i couldn’t understand it ,and haven’t found a proper explanation about it online.
function or(b1, b2) {
if (b1 == false && b2 == false) return false;
else return b1 ? b1 : b2;
}
3.Here are the coding tests, and the code above passed all of them. But would anyone tell me the logic of b1 ? b1 : b2. I am a beginner, please help me !
//TEST 1
actual = or("bananas", false);
expected = "bananas";
if (actual === expected) {
console.log("Yay! Test PASSED.");
} else {
console.error("Test FAILED. Keep trying!");
console.log(" actual: ", actual);
console.log(" expected: ", expected);
}
//TEST 2
actual = or("", "bananas");
expected = "bananas";
if (actual === expected) {
console.log("Yay! Test PASSED.");
} else {
console.error("Test FAILED. Keep trying!");
console.log(" actual: ", actual);
console.log(" expected: ", expected);
}
//TEST 3
actual = or(true, true);
expected = true;
if (actual === expected) {
console.log("Yay! Test PASSED.");
} else {
console.error("Test FAILED. Keep trying!");
console.log(" actual: ", actual);
console.log(" expected: ", expected);
}
//TEST 4
actual = or(true, false);
expected = true;
if (actual === expected) {
console.log("Yay! Test PASSED.");
} else {
console.error("Test FAILED. Keep trying!");
console.log(" actual: ", actual);
console.log(" expected: ", expected);
}