Complex conditions in shortened form in JavaScript
In shortened form, you can use the operators
&& and ||.
See an example:
javascriptlet test1 = true;
let test2 = true;
if (test1 && test2) {
console.log('+++');
} else {
console.log('---');
}
Another example:
javascriptlet test1 = true;
let test2 = true;
if (test1 || test2) {
console.log('+++');
} else {
console.log('---');
}
Задание 1
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
if (test1 === true && test2 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 2
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
if (test1 === true && test2 !== true) {
console.log('+++');
} else {
console.log('---');
}
Задание 3
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
if (test1 !== true && test2 !== true) {
console.log('+++');
} else {
console.log('---');
}
Задание 4
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
if (test1 !== false && test2 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 5
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true && test2 === true && test3 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 6
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true || test2 === true && test3 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 7
Rewrite the following code in shortened form:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true || test2 === false && test3 === false) {
console.log('+++');
} else {
console.log('---');
}