-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logical_Operators.js
60 lines (50 loc) · 1.41 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
// =====================
// LOGICAL AND OPERATOR =true is all operands are true
// =====================
const password = prompt("Enter your password");
if (password.length >= 6 && password.indexOf(' ') === -1) {
console.log("VALID PASSWORD!");
} else {
console.log("INCORRECT FORMAT FOR PASSWORD!");
}
// =====================
// LOGICAL OR OPERATOR = true is Any one is true
// =====================
let vari=8;
if (vari===8 || vari===9){
console.log("Auspicious Numbers");
}else{
console.log("meh");
}
// =====================
// LOGICAL NOT OPERATOR = if something is true it returns false, and vice-versa
// =====================
let firstName = prompt("enter your first name");
if (!firstName) { //if nothing is enter then firstname is an empty string i.e. false
firstName = prompt("TRY AGAIN!!!");
}
// =====================
// COMBINING && and ||
// =====================
const age = 8;
if (!(age >= 0 && age < 5 || age >= 65)) {
console.log("YOU ARE NOT A BABY OR A SENIOR!");
}
// =====================
// AGEWISE PRICE EXAMPLE
// =====================
//constraints
// 0-5 BABY =free
// 5-10 CHILD =$10
// 10-65 ADULT =$20
// 65+ SENIOR CITIZEN =free
const age = 100;
if ((age >= 0 && age < 5) || age >= 65) {
console.log("FREE");
} else if (age >= 5 && age < 10) {
console.log("$10");
} else if (age >= 10 && age < 65) {
console.log("$20");
} else {
console.log("INVALID AGE!");
}