-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditions.js
More file actions
94 lines (60 loc) · 2.59 KB
/
Copy pathconditions.js
File metadata and controls
94 lines (60 loc) · 2.59 KB
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
// if else if - is a type of control flow statement.
// it called conditional statement or in easy word ~ decision making flow.
//first you declare a variable
// ===== THE DIRECT ACTION TYPE
let perTablePerson = 2;
if (perTablePerson <= 2 ) {
console.log("Would you like a table for two, sir?");
} else if ( perTablePerson <= 6 ) {
console.log("Would you like a large grouptable?");
} else {
console.log("Sorry! We're already reserved for today!")
}
//variable initialization - creating intentionally empty box;
// ==== THE STATE MUTATION TYPE
let score = 10;
let cheerUp = "Briar! Briar! Briar!" ;
let boo = "The team score is down!" ;
let finalMsg = "";
// this is an empty variable it's reserved slot in memory.
if (score <= 5) {
finalMsg = boo; // here we ressignmemt that slot, in cs term - variable mutation.
// In easy words, changing or overwriting the data that was perviously stored in memory slot.
} else {
finalMsg = cheerUp;
}
console.log(finalMsg);
// using console for send data out to user!
// without adding console in last you can't see the output in device.
//====== THE FUNCTIONAL TYPE
// return only works inside a function
// here we create a function - like creating a recipe (the definition).
// function -is naming the recipe.
// internal logic inside it -is the recipe.
// the execution line - console log - like ordering the food.
function checkTeamStatus () {
if (score <= 5) {
return boo;
}else {
return cheerUp;
}
}
console.log(checkTeamStatus());
//=== CONDITIONAL STATEMENTS has 4 types
// 1. if/ else if/ else - checking ranges of data (e.g., score >= 50)
// 2. switch - matching one box against many exact text/number options
// 3. Ternary Operator(? :) - shrinking a simple if/else down into one short line
// 4. Logical short-circuiting - setting up quick backup values if data goes missing.
// Already covered first two types above
//The ternary operator does same job in one single line. the word "ternary" just means "three parts".
//let finalMsg = (score <= 5) ? boo : cheerUp; - comment out cause finalMsg is already declared above it will show an error.
let playerScore = 2;
let playerWins = "Yay! You get level up."
let playerLoses = "Oops! You lose it"
let dashboardScore = (playerScore <= 2) ? playerWins : playerLoses;
console.log(dashboardScore);
/* ======== Logical short-circuiting (||) ========= */
// It uses the OR || operator to instantly make a choice without writing any if or else keywords at all.
let userNickname = null;
let displayName = userNickname || "GuestPlayer" ;
console.log(displayName);