-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmis2.js
149 lines (118 loc) · 4.03 KB
/
mis2.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
// Q: - Can we go over how and where we need to apply rules for making our websites compatible for different screen sizes?
// A: Two things to be mindful of this weekend:
// 1) I want you all to try avoid using absolute measurements, and begin using more relative measurements.
// Relative measurements:
// %
// em
// rem
// 2) I want you all to start thinking about your website in the context of either flexboxes or using CSS grid.
// Q: - Why would you ever use an object over an array given that it is more difficult to create?
// A:
// Objects are meant to be used to label data.
// Arrays are meant to be group unorganized and unlabeled data.
// let studentNames = ["Anthony", "Sarah", "Phoenix", "Rachel"]
// let instructorsOf2304 = {
// leadInstructorOne: "Elle Oshiro",
// leadInstructorTwo: "Ed Haddican",
// mentor: "Tri Le"
// }
// OBJECTS REVIEW
// Creating an object
// let talkingMeowth = {
// name: "Meowth",
// age: 20,
// isHero: true,
// friends: ["Jessie", "James"],
// hasChildren: undefined
// }
// Object notation
// Dot notation
// Skeleton Syntax:
// nameOfYourObj.nameOfTheKey
// Note: Dot notation will ALWAYS look for the key name that matches exactly what you wrote after the dot (aka period).
// Bracket notation
// Skeleton Syntax:
// nameOfYourObj["nameOfYourKey"]
// Note: Bracket notation CAN use variables that are storing key names.
// let theKeyImLookingFor = "name";
// DOT NOTATION
// console.log(talkingMeowth.name)
// Both console.logs below won't work because the key name after the period does not exist in the object.
// console.log(talkingMeowth.theKeyImLookingFor)
// console.log(talkingMeowth.someVariable)
// BRACKET NOTATION
// console.log(talkingMeowth["name"])
// console.log(talkingMeowth[theKeyImLookingFor])
// OBJECT METHODS (AKA FUNCTIONS ON AN OBJECT)
let talkingMeowth = {
name: "Meowth",
age: 20,
isHero: true,
friends: ["Jessie", "James"],
hasChildren: undefined,
sayCatchphrase: function () {
console.log("Team Rocket is blasting off again!")
},
haveBirthday: undefined
}
// Skeleton Syntax for an object method:
// Example:
// Dot notation first:
// nameOfYourObject.nameOfTheObjMethod()
// Bracket notation first:
// Skeleton Syntax:
// nameOfYourObject["nameOfYourMethod"]()
// Dot notation
// talkingMeowth.sayCatchphrase()
// Bracket notation
// talkingMeowth["sayCatchphrase"]()
// Sub-Point: How do you declare a function outside of an object, and then put the function into the object?
// function haveBirthday() {
// talkingMeowth.age = talkingMeowth.age + 1;
// console.log(talkingMeowth.age)
// }
// console.log(talkingMeowth)
// talkingMeowth.haveBirthday = haveBirthday
// console.log(talkingMeowth)
// THE 'THIS' KEYWORD
// Definition: This, in coding, is a contextual keyword that refers to the context of the object around it.
// let newPhoneSpecs = {
// versionNum: 14,
// screenSize: 6,
// company: "Apple",
// getPhoneSpecs: function () {
// console.log({
// versionNum: newPhoneSpecs.versionNum,
// screenSize: this.screenSize,
// company: this.company
// })
// }
// }
// let superBasicObj = {
// getBasicObjSpecs: function() {
// console.log(this)
// }
// }
// // newPhoneSpecs.getPhoneSpecs()
// superBasicObj.getBasicObjSpecs()
// NEW JS MATERIAL: MULTIDIMENSIONAL ARRAYS (AKA 3D ARRAYS)
// For Context: 2d arrays (AKA single-dimensional arrays) -->
let singleDimArray = [1, 2, 3, 4, 5];
let multiDimArray = [
[1, 2],
[3],
[4, 5]
]
let partyRSVPs = [
["Elle", "Baby Sister"],
["Bob"],
["Mom", "Dad"]
]
// console.log(partyRSVPs[0])
// console.log(partyRSVPs[2])
// console.log(partyRSVPs[1])
// partyRSVPs[0]
// ===
// ["Elle", "Baby Sister"]
// console.log(partyRSVPs[0][1])
console.log(partyRSVPs[2][0])