Mit if und else entscheiden
Prüfe eine Bedingung, um festzustellen, welcher Schritt als Nächstes ausgeführt wird.
Ein einfaches Beispiel
Am Anfang2 < 3
Ergebnis1
if (2 < 3) {
console.log(1);
} else {
console.log(0);
}
1
Anzeigen
Beispiele aus dem Alltag
Eine Familie braucht 4 Sitzplätze, aber nur 3 sind frei. Gib 1 aus, wenn alle Platz haben, sonst 0.
Am Anfang4 → 3
Ergebnis0
const needed = 4;
const free = 3;
if (needed <= free) {
console.log(1);
} else {
console.log(0);
}
0