-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconditionals.js
134 lines (90 loc) · 2.26 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
What are conditionals?
- Look at a condition (evaluate a set of values)
- They will determine if its a true statement or a false one
*/
let num = 7
console.log(7 < 5) // true or false -- Boolean
let bool = true
console.log(bool)
/*
less than/greater than - <, >
less than or equal to: <=, >=
Not operator: !
Is equal: ==, ===
Not Equal: !==
LOGIC OPERATORS
AND - &&
OR - ||
*/
console.log(!bool)
let myFavNum = 3
let aNum = 4
console.log('Are they the same? ', (myFavNum == aNum))
myFavNum = myFavNum + 1
console.log('Are they the same, now? ', (myFavNum == aNum))
let timeOfDay = "lunch"
let weather = "rainy"
// T && F
let outside = (timeOfDay === "lunch" && weather ==="clear")
console.log("Should I go outside?", outside )
// T || F
let outside2 = (timeOfDay === "lunch" || weather ==="clear")
console.log("Should I go outside?", outside2 )
/*
Conditional Statements
if (condition) {
do a true thing
} else {
do this thing for false
}
*/
let score = 30
if ( score >= 90 ) {
console.log('You got an A!')
} else if ( score >= 80) {
console.log('You got a B!')
} else if ( score >= 70 ) {
console.log('You got a C!')
} else if ( score >= 60 ) {
console.log('You got a D...')
} else {
console.log('You got a F...')
}
// let a=3, b=4, c=5
// !(a < b) && c + 27 > 42
// 5 + false
// !(3 < 4) && 32 > 42 || true
// ! (true) && false || true
// false && (false || true)
// false || true
// true
let x = 5
console.log(x)
x = x + 1
console.log(x)
x -= 7 // subracts 7 from x ( x = x - 7)
console.log(x)
x++
// x--
console.log(x)
/* Loops */
console.log('----- Loops')
// Starting Point
// How long does the loop run
// Body of the Loop (what the loop does)
// Tell the loop to move to the next pass
// Do this but in a loop:
// console.log('T-9..')
// console.log('T-8..')
// console.log('T-7..')
// console.log('T-6..')
let count = 10
while ( count > 0 ) {
console.log(`T-${count}..`) // "T-" + count + ".."
count-- // count = count - 1
}
// for ( starting point; condition; update)
for (let count = 10; count > 0; count--) {
console.log("T-" + count + "..")
}