-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFCC notes.js
182 lines (154 loc) · 4.15 KB
/
FCC notes.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function tryMe() {
console.log("hello world");
}
tryMe();
function testParamArg(param1, param2) {
console.log("param1","param2");
}
testParamArg("andre","ganteng");
var myGlobal = 5;
function testFunction() {
var local = "foo";
console.log(local);
}
testFunction();
console.log(local);
//pass values into a function with arguments
function plusThree(num){
return num + 3;
}
var answer = plusThree(3); //8
function timesFive(a) {
return a * 5;
}
console.log(timesFive(3));
/*
queue
is an abstract data structure where items are kept in (an) order
new items are added to the back of queue
old items are taken off front of queue*/
//still need to figure out what the fuck the stand in line lesson means
//Conditional Logic with IF statements
//the keyword "if" tells JS to execute the "statement" (code in curly brackets) under certain "conditions" only,
//which is defined in parentheses, and is Boolean
//when condition is true, statement will execute
//when condition is false, statement will not execute
/*
if (condition is met) {
statement is executed;
}
*/
function test(myCondition) {
if (myCondition) {
return "it was true";
}
return "it was false";
}
/*Comparison operators, all Boolean
the most basic: == "equality" operator
meaning: if equivalent, true
if not equal, false
different the singular = sign, which is an "assignment" operator
"strict equality" operator: ===
"inequality" operator: !=
"greater than" operator: >
"less than" operator: <
"greater than or equal to" operator >=
"logical and" operator: &&
this operator is to validate function with more than one statements/conditions
*/
if (num > 5 && num < 10) {
return "yes";
}
return "no"
;
/*
"logical or" operator: ||
*/
if (num < 10 || num < 5) {
return "no";
}
return "yes";
/*
else statements
if condition is true, then statement will execute. If false, then it will not execute.
Else statements give an alternate statement to execute, if false.
*/
if (num > 3) {
return "bigger than 3";
}
else {
return "3 or less";
}
// else if statements can give yet another condition and statement if false, and can be chained indefinitely for complex computing
function ladiesLike(dickSize) {
if (dickSize < 5) {
return "tiny";
} else if (dickSize < 10) {
return "small";
} else if (dickSize < 15) {
return "medium";
} else if (dickSize < 20) {
return "large";
} else {
return "the one mama wants";
}
}
ladiesLike(11);
// you can determine the type of variable/value with the typeof operator, typeof 3;
//Golf Code
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
// Only change code below this line
if (strokes == 1) {
return "Hole-in-one!";
} else if (strokes <= par -2) {
return "Eagle";
} else if (strokes == par -1) {
return "Birdie";
} else if (strokes == par) {
return "Par";
} else if (strokes == par +1) {
return "Bogey";
} else if (strokes == par +2) {
return "Double Bogey";
} else {
return "Go Home!";
}
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
//SWITCH STATEMENTS, used if you have many options to choose from
//OBJECTS
//Accessing Object properties with variables
var dogs = {
Fido: "Mutt",
Hunter: "Doberman",
Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog] //accessing dogs[Hunter] using bracket notation
console.log(myBreed); //will print "Doberman"
//Another way to do this:
var someObj = {
propName: "John"
};
function propPrefix(str) {
var s = "prop";
return s + "str";
}
var someProp = propPrefix("Name"); //propPrefix + name argument creates property name "propName"
console.log(someObj[someProp]);
//Updating Object Properties -> using dot notation or bracket notation
var myDog = {
'name': 'Kaya',
'breed': 'Balinese',
'color': 'brown',
'friends': ['Mona']
}
myDog.name = 'Kaya Anjing'; //or
myDog['name'] = 'Kaya Anjing';
//Add new Properties -> same as updating object properties
//Delete Properties
delete myDog.color;