-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.js
More file actions
443 lines (356 loc) · 11.8 KB
/
practice.js
File metadata and controls
443 lines (356 loc) · 11.8 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
alert("Once Upon a time there were some intrepid explorers who wandered into the amazon")
prompt("Hello, what's your name?")
var yourName = "Francisco"
`Hello ${yourName} Lets go exploring!`
var adjective = "funny"
var noun = "man"
var liquid = "hennesy"
var bodyPart = "elbow"
var verb = "smell"
var noun1 = "jar"
var place = "la la land"
`Once Upon a time there were some intrepid explorers who wandered into the amazon. They found some amazing things! Piranhas are more ${adjective} during the day, so make sure you cross the ${noun} at night. Piranhas are attracted to fresh ${liquid} and will most likely take a bite out of your ${bodyPart} if you ${verb}. Whatever you do, if you have an open ${noun1} try and find another way to get back to ${place}. Good luck!`
// strict equality operators ===
// asking the questions are these things the same?
3 === 4
// output: false
15 === 15
// output: true
//boolean value is true or false
// relation operators < >
//asking the question is this thing greater than the other thing?
3 > 4
// output: false
3 < 4
// output: true
// conditional statement - a tool that can evaluate a condition and return a response
// aka if/else statements
// if - first keyword in a conditional statment
// if(condition is true) {
// do this action
// }
// ELSE IF - allows for additional conditional statemnets
//else if(condition is true) {
// do this action
// }
// else - catch all, default response that covers
// else {
// do this action
// }
// age checker conditional statement
va myAge = 21
if(myAge > 21) {
alert("you can drink, vote, and learn how to code!")
} else if(myAge > 17) {
alert("go vote and code but no drinking alchohol")
} else {
alert("woohoo, you can still learn how to code but you're too young tp drink and vote!")
}
// console.log() - great for bug fixing, displays things
console.log(myAge)
var myName = prompt("Hi, what's your name?")
var myResponse = prompt("Do you know how to write code?")
if(myResponse === "yes") {
alert(`you will rule the world, ${myName}`)
} else if(myResponse === "no") {
alert("well good luck with that.")
}
// FUNCTION - little coding machines, reusable blocks of code
// Process
// const - variable declaration
// function name with assignment operator
// () - pass data through the function
// => arrow syntax, replaces the keyword function
// {} code block, this area we write our code
// return - tells the function where to end, what to give as output
// function call - function name with ()
// example
// const myFunction = () => {
// return this code block
// }
// myFunction()
//As a group – write a function that asks the user a question and returns an answer
//As a user, I see a prompt where I can ask a question
//As a user, I see an alert that tells me a random Magic 8 Ball answer
//Better not tell you now
// It is decidedly so
// Don’t count on it
// Signs point to yes
// Outlook not so good
//create a function
//const magic8 = () => {return}
// math.random() - generates a random number betwwen 0 and 0.9
Math.random()
// output : 0.3729987987
Math.random()
// output : .04987987928374
// multiply by a whole number
Math.random() * 5
// output: 4.2265787369
// use a method to round the result to a whole number
// math.floor() rounds down to the nearest whole number
Math.floor(4.2265787369)
// output: 4
Math.floor(4.988888)
//output: 4
//const magic8 = () => {
// return Math.floor(math.random() * 5)
// }
// magic8 = ()
//use a variable to store the random number
// const magic8 = () => {
// var randomNum = Math.floor(math.random() * 5 )
// return randomNum
// }
// magic8()
// use conditional statments to output the different response
const magic8 = () => {
var randomNum = Math.floor(math.random() * 5 )
// return randomNum
if(random.Num === 0) { return "better not tell you now"
} else if (randomNum === 1) {
return "it is decidely so."
} else if (randomNum === 2) { return "dont count on it"
} else if (randomNum === 3) { return "signs point yes"
} else if (randomNum === 4) {
return "outlook not so good"
}
}
magic8()
var myName = prompt("Hi, what's your name?")
var myResponse = prompt("Do you know how to write code?")
if(myResponse === "yes") {
alert(`you will rule the world, ${myName}`)
} else if(myResponse === "no") {
alert("well good luck with that.")
}
myName()
// JavaScript -- Jumpstart May 2022
// Created in 1995 Brenden Eich and Netscape.
// Java and JavaScript are different languages
// JavaScript has become the international standard for scripting languges and is included in almost every HTML website.
// ECMAScripting language 6
// A scripting languge that is dynamically typed, and interperted
// JavaScript can accept inputs and give us outputs.
// WHAT of JavaScript
// JavasScript Data Types
// Numbers
1234
// addition +
1 + 1
5023 + 1234
// --> output 6257
// subtraction -
5023 - 1234
// --> output 3789
// multiplcation *
5023 * 1234
// --> output 6198382
//division /
5023 / 1234
// --> output 4.070502431118315
// Exponents **
5023 ** 3
// --> output 126732947167
// Modulo %
5023 % 3
// --> output 1
7 % 3
// --> output 1
// JS follows PEMDAS as it orders it's operations
7 * (8 + 9) - 10
// output --> 109
// Strings - a "string" (bunch) of characters put together
// Strings are pieces of information that are shown as text
// String symbol is - ""
"Austin"
"my name"
" " // spaces are characters
"Hello how are y'all doing?"
"This + that"
// Boolean
// Bool was a mathematician that invented a kind of algrebra that utelized only 1's and 0's as true and false values.
true
false
//HOW of JavaScript
// Variable - a placeholder for some data
// variable declaration - var
// "hey javascript I am gioving you a new variable to work with"
// var
// variable name
// a custom name that we as the developers come up with for this variable
// names must always use the casing concention called camelCase
// var dogName
// var mayJumpstartTewentyTwentyTwo
// var number
// the assignment operator =
// var dogName =
// the data itself
var dogName = "Sheldon"
// ---> output "Sheldon"
// String Interpolation
// uses back tic's as the wrapper for the String
// uses $ and curly brackets { }
`Hey get out of the trash ${dogName}`
var userName = "purple_Alligator"
`Welcome back, ${userName}`
// --> output 'Welcome back, purple_Alligator'
userName = "rickSanchez95"
`Welcome back, ${userName}`
// --> output 'Welcome back, rickSanchez95'
// Built-in Methods
alert()
prompt()
// built in methods can take data as arguments.
alert("Hello World")
prompt("How are you?")
var promptResponse = prompt("How are you?")
`Austin said ${promptResponse}`
// STRICT EQUALITY OPERATORS ===
// Asking the question are these things the same?
3 === 4
// Output: false
15 === 15
// Output: true
// Boolean value is true or false
// RELATIONAL OPERATORS < >
// Asking the question is this thing greater than the other thing?
3 > 4
// Output: false
3 < 4
// Output: true
// CONDITIONAL STATEMENTS - a tool that evaluate a condition and return a response
// aka if/else statements
// IF - first keyword in a conditional statement
// if(condition is true) {
// do this action
// }
// ELSE IF - allows for additional conditional statements
// else if(condition is true) {
// do this action
// }
// ELSE - catch all, default response that covers every other possible condition
// else {
// do this action
// }
// age checker conditional statement
var myAge = 21
if(myAge > 20) {
alert("You can drink, vote, and learn how to code!")
} else if(myAge > 17) {
alert("Go vote and code but no drinking alcohol!")
} else {
alert("Woohoo, you can still learn how to code but you're too young to drink and vote!")
}
// Output: "You can drink, vote, and learn how to code!"
// Indentation is meant for readability.
// if(myAge > 20){alert("You can drink, vote, and learn how to code!")} else if(myAge > 17){alert("Go vote and code but no drinking alcohol!")}else{alert("Woohoo, you can still learn how to code but you're too young to drink and vote!")
// }
// console.log() - great for bug fixing, displays things
var myAge = 16
console.log(myAge)
// Output: 16
// FUNCTIONS - little coding machines, reusable blocks of code
// Process
// const - variable declaration
// function name with assignment operator
// () - pass data through the function
// => arrow syntax, replaces the keyword function
// {} code block, this area we write our code
// return - tells the function where to end, what to give as an output
// function call - function name with ()
// Example
// const myFunction = () => {
// return this code block
// }
// myFunction()
// Magic 8 ball function
// As a group – write a function that asks the user a question and returns an answer
// As a user, I see a prompt where I can ask a question
// As a user, I see an alert that tells me a random Magic 8 Ball answer
// Better not tell you now
// It is decidedly so
// Don't count on it
// Signs point to yes
// Outlook not so good
// Create a function
// const magic8 = () => {return }
// Use of Math.random()
// Math.random() - generates a random number between 0 and 0.9
Math.random()
// Output: 0.3737220387287852
Math.random()
// Output: 0.4958474102345065
// Multiply by a whole number
Math.random() * 5
// Output: 4.226587873691752
// Use a method to round the results to a whole number
// Math.floor() rounds down to the nearest whole number
Math.floor(4.226587873691752)
// Output: 4
Math.floor(4.988888)
// Output: 4
// const magic8 = () => {
// return Math.floor(Math.random() * 5)
// }
// magic8()
// use a variable to store the random numbers
// const magic8 = () => {
// var randomNum = Math.floor(Math.random() * 5)
// return randomNum
// }
// magic8()
// use conditional statements to output the different responses
// const magic8 = () => {
// var randomNum = Math.floor(Math.random() * 5)
// // return randomNum
// if(randomNum === 0) {
// return "Better not tell you now"
// } else if(randomNum === 1) {
// return "It is decidedly so"
// } else if(randomNum === 2) {
// return "Don't count on it"
// } else if(randomNum === 3) {
// return "Signs point to yes"
// } else if(randomNum === 4) {
// return "Outlook not so good"
// }
// }
// magic8()
// use console.log to see the randomNum passed to the function
const magic8 = () => {
var randomNum = Math.floor(Math.random() * 5)
console.log(randomNum)
if(randomNum === 0) {
return "Better not tell you now"
} else if(randomNum === 1) {
return "It is decidedly so"
} else if(randomNum === 2) {
return "Don't count on it"
} else if(randomNum === 3) {
return "Signs point to yes"
} else if(randomNum === 4) {
return "Outlook not so good"
}
}
console.log(magic8())
var myName = prompt("Hi, what's your name?")
var myResponse = prompt("Do you know how to write code?")
if(myResponse === "yes") {
alert(`you will rule the world, ${myName}`)
} else if(myResponse === "no") {
alert("well good luck with that.")
const myName = (worldDomination) => {
if(randomNum === 0) {
return "Better not tell you now"
} else if(randomNum === 1) {
return "It is decidedly so"
} else if(randomNum === 2) {
return "Don't count on it"
} else if(randomNum === 3) {
return "Signs point to yes"
} else if(randomNum === 4) {
return "Outlook not so good"
}
}
console.log(magic8())