-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
112 lines (85 loc) · 3.65 KB
/
example.js
File metadata and controls
112 lines (85 loc) · 3.65 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
console.log('example ready🏪')
// Reference Data Types (Collections)
// Arrays (Think Ordered lists)
// Data is stored in order, and accessed by position (index)
let numArray = [1, 2, 3, 5, 50, 1000]
let strArray = ['Hey', 'Howdy', '🤠👋']
let mixedArray = [10, 'sumthin', false, ['🦧', '🐒']]
console.log(mixedArray[0]) // 10
// Modify the array
strArray.push('👋🐒') // adds element to the end
strArray.unshift('🧑🏫') // adds element to the beginning
strArray.pop() // removes the last item from the array
strArray.shift() // removes the first item from the array
// Objects (Think Dictionaries)
// Data is stored *un*ordered, and accessed by KEY
let numObj = { first: 5, second: 10, third: 100, last: -500 }
let mickObj = {
fullName: 'Mick McCool',
age: 31.99999,
likes: ['DnD🐉', 'Crocs🐊', 'Anime🥷'],
currentCrocs: {
name: "Akatsuki Naruto Shippuden Crocs",
size: 11
},
greeting: function () {
console.log("Howdy 👋🦧")
}
}
console.log(mickObj.currentCrocs.name) // Akatsuki Naruto Shippuden Crocs
// let objThatLooksLikeAnArray = { 0: 'hi', 1: 'howdy', 2: 'what am i doing?' }
let crazyKeyObj = {
thisIsAReallyLongKeyItContainsNoSpacesOrSpecialCharacters: "boop",
"Then i can create a key that has spaces and characters!!": "beep"
}
mickObj.favoriteFood = '🍕' // Add a KEY:VALUE pair to an object
delete mickObj.favoriteFood // Remove a KEY:VALUE pair from an object
// Looping
// start ; Continue while ; increment by (speed)
for (let count = 0; count < 10; count += 5) {
console.log('👋', count)
}
console.log('loop over')
let jeremysCats = [
'😺Iron Man', '🙀Georgie', '😹Hawk Eye', '😼Gopher', '😽Falcon', '😸Remona', '😸Red Hulk', '😿Sad Man',
'😺Captain Meowvel', '🙀Black Panther', '😹Spider-Cat', '😼Thor', '😽Loki', '😸Winter Soldier', '😸Vision', '😿Scarlet Witch',
'😺Ant-Cat', '🙀Wasp', '😹Doctor Strange', '😼Star-Lord', '😽Gamora', '😸Rocket', '😸Groot', '😿Drax',
'😺Mantis', '🙀Nebula', '😹Yondu', '😼Shuri', '😽Okoye', '😸Valkyrie', '😸Korg', '😿Miek',
'😺Nick Furry', '🙀Maria Hill', '😹Phil Coulson', '😼Peggy Carter', '😽Howard Stark', '😸Happy Hogan', '😸Pepper Potts', '😿Jane Foster',
'😺Heimdall', '🙀Sif', '😹Frigga', '😼Odin', '😽Ultron', '😸Thanos', '😸Ronan', '😿Hela',
'😺Ego', '🙀The Collector', '😹Grandmaster', '😼Red Skull', '😽Crossbones', '😸Zemo', '😸Taskmaster', '😿Ghost',
'😺Yellowjacket', '🙀Abomination', '😹Whiplash', '😼Justin Hammer', '😽Mandarin', '😸Aldrich Killian', '😸Malekith', '😿Kurse'
]
// 😿 🍖
// 🙀 🌾
// 😼 🍣
// This is bad, this should be replaced with a loop
// jeremysCats[0] += '🐟'
// jeremysCats[1] += '🐟'
// jeremysCats[2] += '🐟'
// jeremysCats[3] += '🐟'
// jeremysCats[4] += '🐟'
// jeremysCats[5] += '🐟'
// jeremysCats[6] += '🐟'
// "Feeds" all of jeremy's cats
function feedCats() {
for (let catNumber = 0; catNumber < jeremysCats.length; catNumber += 1) {
jeremysCats[catNumber] += '🐟'
}
}
// "Feeds" all of jeremy's cats based on their "mood"
function feedCatsComplex() {
for (let catNumber = 0; catNumber < jeremysCats.length; catNumber += 1) {
// look for sad cats
if (jeremysCats[catNumber].includes('😿')) {
jeremysCats[catNumber] += '🍖'
} else if (jeremysCats[catNumber].includes('🙀')) {
jeremysCats[catNumber] += '🌾'
} else if (jeremysCats[catNumber].includes('😼')) {
jeremysCats[catNumber] += '🍣'
} else {
jeremysCats[catNumber] += '🐟'
}
console.log(catNumber, jeremysCats[catNumber])
}
}