-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
291 lines (187 loc) · 5.96 KB
/
index.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
///// Running Code Practice /////
/*
In this file, there are 10 problems to complete.
Each of them has instructions and a place to
code below those instructions. Complete as many
of the problems as you can.
These problems are themed around your fictional
internet service. This is just to make the
problems more interesting, not because it will
actually change anything about your internet.
Reminder: when you're working with a partner,
don't be afraid to ask questions! You'll both
learn from talking about code and from teaching
each other.
*/
///// PROBLEM 1 /////
/*
Create a variable that will store the download
speed of your internet connection.
Call the variable 'speed' and set its value
to 25.
This speed can change, so we need to make sure
to use a keyword that will allow us to reassign
the value.
*/
// CODE HERE
//let Speed = 25
///// PROBLEM 2 /////
/*
Congrats! You just upgraded your internet plan
to the platinum level.
Reassign the value of 'speed' to be 500.
Log speed to the console and run your file to
see the change.
Hint: in your terminal, make sure you're in the
directory where this file is saved. Use node to
run the file with this command: `node index.js`.
*/
// CODE HERE
let Speed = 500;
console.log(Speed)
///// PROBLEM 3 /////
/*
You're going to be watching a lot more sports
now that you have this sweet high-speed
connection. Or maybe a lot more YouTube...
Either way, you're going to need some snacks.
Create a variable called 'faveSnack' and set its
value to be a string of your favorite snack.
Reminder: this could change, so be careful about
which keyword you use to declare this variable.
*/
// CODE HERE
let faveSnack = "Chips"
///// PROBLEM 4 /////
/*
While you're thinking about snacks, we should
also take note of your favorite drink.
Create a variable called 'faveDrink' and set its
value to be a string of your favorite drink.
Reminder: this could change, so be careful about
which keyword you use to declare this variable.
*/
// CODE HERE
let faveDrink = "Water"
///// PROBLEM 5 /////
/*
Now let's create a variable that will never
change. We want to make sure that our network
is always private.
Create a variable called 'private' and set it
to the boolean true.
Remember, we don't want this to ever change, so
be sure to use a keyword that will prevent change.
*/
// CODE HERE
let private = true
///// PROBLEM 6 /////
/*
Now let's figure out all of your subscriptions.
The price on your internet went up, so you
want to save a little bit of money elsewhere.
You're subscribed to the following services for
the prices listed next to them.
Monthly Fees
------------
$15 Netflix
$7 Hulu
$5 Disney+
$10 YouTube Premium
$10 Peacock
Create a variable for each subscription. The
value of each variable should the monthly cost
of that subscription.
For example:
let appleTv = 10;
*/
// CODE HERE
let Netflix = 15;
let Hulu = 7;
let Disney = 5;
let Youtube = 10;
let Peacock = 10;
///// PROBLEM 7 /////
/*
Let's find out what your total cost is.
Create a variable called 'total' whose
value is all of your subscription variables
added together.
Then console log total to see the value.
*/
// CODE HERE
let total = Netflix + Hulu + Disney + Youtube + Peacock
console.log(total)
///// PROBLEM 8 /////
/*
You make some tough choices. Reassign the values
of your variables to reflect the following
information:
- you cancel Hulu, it's now $0/month
- you downgrade Peacock, it's now $5/month
- you downgrade Netflix, it's now $8/month
Challenge: instead of explicitly reassigning
values, use mathematical operators. For example:
appleTv = appleTv - 5
or
appleTv -= 5
*/
// CODE HERE
Hulu -=0
Peacock -=5
Netflix -=8
///// PROBLEM 9 /////
/*
You might be able to guess what's coming next.
We're going to make a variable to store
the new total of your subscriptions.
Create a variable called 'newTotal' and set its
value to all of your subscription variables
added together.
*/
// CODE HERE
let newTotal = Netflix + Hulu + Disney + Youtube + Peacock
///// PROBLEM 9: Bonus Section /////
/*
Perhaps you're curious about why we created
both 'total' and 'newTotal' seeing as we assigned
them both to be all the subscriptions vairables
summed together. But do they have the same value?
Let's find out. Un-comment the console.logs below
and compare the numbers.
*/
console.log('Total: ', total)
console.log('New Total: ', newTotal)
/*
What is happening here? When we run a file
using node, it's reading from the top down.
'total' is declared before any changes are
made to the subscription variables, and the
original total is saved in memory. Any time
after that declaration that we want to access
'total', it will still reference the original
value. It doesn't care what happens to the
variable values that make it up. When we made
'newTotal', we were further down in the file
and were now referencing the new values of the
subscription variables.
This concept can be confusing, but will sink
in over time!
*/
///// PROBLEM 10 /////
/*
Finally, let's figure out what your savings
are. We would like to know what percent
you'll be saving.
Create a variable called 'savings' whose
value is the percent that you're saving.
You answer can be in this format: xx.xxxxxx
i.e. Don't worry about rounding it
or actually giving it a percent sign.
For example, if our original total was 100
and our new was 85, then we would be saving
15%.
*/
// CODE HERE
let savings = 47%34
console.log(savings)