-
Notifications
You must be signed in to change notification settings - Fork 0
/
logical operators.js
67 lines (44 loc) · 1.08 KB
/
logical operators.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
let hour = 12;
let isWeekend = true;
if (hour < 11 || hour > 20 || isWeekend) {
alert('The office is closed.'); // it is the weekend
}
currentUser = null;
defaultUser = "Sandra";
name = currentUser || defaultUser || "unnamed";
console.log(name);
(name); // selects "Sandra" – the first truthy value
let x;
true || (x = 1);
console.log(x);
(x); // undefined, because (x = 1) not evaluated
let x;
false || (x = 1);
console.log(x); // 1
let hour = 13;
let minute = 50;
if (hour == 13 && minute == 50) {
console.log(hour && minute);
('The time is 13:50');
}
let x = 3;
(x > 0) && alert('Greater than zero!');
let x = 1;
if (x < 0) {
alert('Greater than zero!');
}
let userName = prompt("Who's there?", '');
if (userName == 'Admin') {
let pass = prompt('Password?', '');
if (pass == 'TheMaster') {
alert('Welcome!');
} else if (pass == '' || pass == null) {
alert('Canceled');
} else {
alert('Wrong password');
}
} else if (userName == '' || userName == null) {
alert('Canceled');
} else {
alert("I don't know you");
}