Zapleteni pogoji v okrajšani obliki v JavaScript
V okrajšani obliki je mogoče uporabiti
operatorje && in ||.
Poglejte primer:
javascriptlet test1 = true;
let test2 = true;
if (test1 && test2) {
console.log('+++');
} else {
console.log('---');
}
Še en primer:
javascriptlet test1 = true;
let test2 = true;
if (test1 || test2) {
console.log('+++');
} else {
console.log('---');
}
Задание 1
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
if (test1 === true && test2 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 2
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
if (test1 === true && test2 !== true) {
console.log('+++');
} else {
console.log('---');
}
Задание 3
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
if (test1 !== true && test2 !== true) {
console.log('+++');
} else {
console.log('---');
}
Задание 4
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
if (test1 !== false && test2 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 5
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true && test2 === true && test3 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 6
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true || test2 === true && test3 === true) {
console.log('+++');
} else {
console.log('---');
}
Задание 7
Prepišite naslednjo kodo v okrajšano obliko:
javascriptlet test1 = true;
let test2 = true;
let test3 = true;
if (test1 === true || test2 === false && test3 === false) {
console.log('+++');
} else {
console.log('---');
}