-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conditionals.js
71 lines (55 loc) · 1.55 KB
/
Conditionals.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
67
68
// =====================
// BASIC IF/ELSE
// =====================
let random = Math.random();
if (random < 0.5) {
console.log("YOUR NUMBER IS LESS THAN 0.5!!!")
} else {
console.log("YOUR NUMBER IS GREATER (OR EQUAL) THAN 0.5!!!")
}
console.log(random);
// =====================
// PROMPT EXAMPLE
// =====================
const dayOfWeek = prompt('ENTER A DAY').toLowerCase();
if (dayOfWeek === 'monday') {
console.log("UGHHH I HATE MONDAYS!")
} else if (dayOfWeek === 'saturday') {
console.log("YAY I LOVE SATURDAYS!")
} else if (dayOfWeek === 'friday') {
console.log("FRIDAYS ARE DECENT, ESPECIALLY AFTER WORK!")
} else {
console.log("MEH")
}
// =====================
// TICKET PRICE EXAMPLE
// =====================
// 0-5 - FREE
// 5 - 10 CHILD $10
// 10 - 65 ADULT $20
// 65+ SENIOR $10
const age = 890;
if (age < 5) {
console.log("You are a baby. You get in for free!")
} else if (age < 10) {
console.log("You are a child. You pay $10")
} else if (age < 65) {
console.log("You are an adult. You pay $20")
} else {
console.log("You are a senior. You pay $10")
}
// =====================
// NESTING CONDITIONALS
// =====================
const password = prompt("please enter a new password");
// Password must be 6+ characters
if (password.length >= 6) {
// Password cannot include space
if (password.indexOf(' ') === -1) {
console.log("Valid Password!");
} else {
console.log("Password cannot contain spaces!")
}
} else {
console.log("PASSWORD TOO SHORT! Must be 6+ characters")
}