-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript-conditionals.js
73 lines (52 loc) · 1.43 KB
/
javascript-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
// Equality Operators
// Strict equality ===
// let myName = "Elyse"
// console.log("Elyse" === myName) // true
// Loose equality ==
let myFavNum = 7
console.log(myFavNum == "7") // true
console.log(myFavNum === "7") // false
// Relational Operations
// < > <= >=
// Logical Operators
// Logical AND is &&
let greeting = "hello"
let num = 6
console.log(num > 2 && "hello" === greeting) // true + true = true
console.log(num < 2 && "hello" === greeting) // false + true = false
// Logical OR is ||
console.log(num < 2 || "hello" === greeting) // false + true = true
// Negation
// Logical opposite using bang operator !
console.log(num !== greeting) // true
// ________________________
// IF/ELSE
if(true) {
console.log("I'm true!")
}
if(false) {
console.log("I'm false!")
} else {
console.log("here is the else")
}
// String interpolation - injects a variable into a string (best practice)
// String concatenation - using the addition sign to add strings and variables: "Hey " + myName
let myName = "Elyse"
myName = "Zack"
if(myName === "Elyse") {
console.log("Hey Elyse!")
} else {
console.log(`Hey ${myName}!`)
}
// ELSE IF
let num1 = 12
let num2 = "12"
if(num1 > num2) {
console.log(`${num1} is greater than ${num2}`)
} else if(num1 < num2) {
console.log(`${num1} is less than ${num2}`)
} else if(num1 === num2) {
console.log(`${num1} and ${num2} are the same`)
} else {
console.log("Invalid entry")
}