-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-conditionals.js
More file actions
42 lines (33 loc) · 886 Bytes
/
03-conditionals.js
File metadata and controls
42 lines (33 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
console.log(typeof true);
// Vergleiche ergeben Wahrheitswerte.
1 == 1;
1 != 0;
1 >= 0;
// `includes` prüft, ob ein Element in einem Array enthalten ist.
["a", "b", "c"].includes("a");
let weather = "Regen";
let action;
if (weather == "Regen") {
action = "Nimm einen Regenschirm mit.";
} else if (weather == "Sonne") {
action = "Nimm eine Sonnenbrille mit.";
} else if (weather == "Schnee") {
action = "Nimm Handschuhe mit.";
} else {
action = "Nimm nichts mit.";
}
// if-else als Ausdruck
let a = 1;
let b = 2;
let c = a > b ? 3 : 4;
// Truthy/Falsy und Short-Circuiting
a || b;
a && b;
// Vervollständigen Sie das Programm.
let x = 7;
"Die Zahl ist gerade.";
"Die Zahl ist ungerade.";
// Programmieren Sie Schere, Stein, Papier.
let choices = ["Schere", "Stein", "Papier"];
let player = "Schere";
let computer = choices[Math.floor(Math.random() * choices.length)];