-
Notifications
You must be signed in to change notification settings - Fork 13
/
class11.html
607 lines (496 loc) · 22.9 KB
/
class11.html
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<!doctype html>
<html lang="en">
<head>
<title>FEWD: Class 11</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/general-assembly.css" id="theme">
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" />
<link rel="stylesheet" href="css/zenburn.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section class="hero">
<h1>HELLO</h1>
<div class="opening-instructions">
<p>1) Please download <a href="../materials/class11.zip">Class 11 Starter Code</a></p>
<p>2) Move the following into your <code class="code">class-work</code> directory:</p>
<p class="pad-left-lg">• <code class="code">first-javascript</code></p>
<p>3) The solution to <code class="code">relaxr</code> is included</p>
</div>
</section>
<section class="hero">
<h1>Class <span class="red">#11</span></h1>
<h1>10/22/2018</h1>
<h1 class="lesson-title">Introduction to JS</h1>
</section>
<!-- ANNOUNCEMENTS -->
<section data-background="#FFF" class="text-left">
<div class="heading">Announcements</div>
<p>• Final Projects:</p>
<div class="pad-left-lg">
<p>⇒ Second deliverable due Monday, October 29th</p>
<p>⇒ Wireframes</p>
</div>
</section>
<!-- QUESTIONS -->
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Questions</div>
</section> -->
<!-- AGENDA -->
<section data-background="#FFF" class="text-left">
<div class="heading">Agenda</div>
<div class="text-smaller">
<p>• <a href="#/intro-to-js">Intro to JS</a></p>
<p>• <a href="#/js-in-the-browser">JS in the browser</a></p>
<p>• <a href="#/intro-to-programming">Intro to programming</a></p>
<p>• <a href="#/pseudo-code">Pseudo code</a></p>
<p>• <a href="#/working-with-js">Working locally with JavaScript</a></p>
<p>• <a href="#/js-basics">JS Basics</a></p>
<p>• <a href="#/document-querying">Document Querying</a></p>
</div>
</section>
<!-- QUESTIONS -->
<!-- <section class="title">
<h1>Questions</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Questions</div>
<div class="text-smaller">
<p class="text-smaller"><b>Q: Why use React or jQuery</b></p>
<p class="text-smallest fragment">A: Depends on the scope and structure of your project; starting off jQuery will suffice for nealry all your project needs. React is useful in large-scale applications with many moving pieces.</p>
</div>
</section> -->
<!-- INTRO TO JAVASCRIPT -->
<section class="title" id="intro-to-js">
<h1>Intro To JavaScript</h1>
</section>
<section class="center">
<img src="img/class08/roller-coaster.png">
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaScript: An Overview</div>
<p>• JavaScript ≠ Java</p>
<p class="fragment">• Born in 1995 - created in 10 days by <a href="https://en.wikipedia.org/wiki/Brendan_Eich" target="_blank">Brendan Eich</a></p>
<p class="fragment">• Most recent version: ECMAScript 2018 (ES9)</p>
<p class="fragment">• JavaScript is one of the most <a target="_blank" href="http://githut.info/">popular languages</a></p>
<p class="fragment">• <a href="https://blog.codinghorror.com/the-principle-of-least-power/" target="_blank">Attwood's Law</a> ⇒ "Any application that can be written in JavaScript, will eventually be written in JavaScript."</p>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaScript: An Overview</div>
<div class="text-smallest">
<p>• Current version is ES8; most developers using a mix of ES5-ES9</p>
<p>• ES ⇒ <a href="http://www.ecma-international.org/" target="_blank">ECMAScript</a> (European Computer Manufacturers Association)</p>
<p>• FEWD will focus on the ES5 implementation</p>
<div class="text-center">
<img src="img/class08/history-javascript.png" alt="">
</div>
</div>
</section>
<section class="title" id="js-in-the-browser">
<h1>JS in the Browser</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaScript: Uses</div>
<p>Most uses of JavaScript fall into four categories:</p>
<div class="pad-left-lg">
<p class="fragment">1) Responding to user actions (events)</p>
<p class="fragment">2) Changing HTML Content</p>
<p class="fragment">3) Changing CSS Styles</p>
<p class="fragment">4) Sending/retrieving data to/from the server</p>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaScript: Uses</div>
<p>A few examples:</p>
<div class="pad-left-lg text-smaller">
<p class="fragment">⇒ Adding / removing elements</p>
<p class="fragment">⇒ Changing CSS on-the-fly</p>
<p class="fragment">⇒ Detecting user interactions (clicks, scrolling, etc.)</p>
<p class="fragment">⇒ Form validation</p>
<p class="fragment">⇒ Loading dynamic content (ex: infinite scroll)</p>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Javascript vs HTML + CSS</div>
<h3>HTML/CSS</h3>
<div class="pad-left-lg">
<p>• HTML/CSS are used to define <u>initial</u> page state</p>
<p>• HTML/CSS are <u>static</u></p>
</div>
<div class="fragment">
<h3>JS</h3>
<div class="pad-left-lg">
<p>• JS is used to define how page state can <u>change</u></p>
<p>• JS is <u>dynamic</u></p>
</div>
</div>
</section>
<!-- INTRO TO PROGRAMMING -->
<section class="title" id="intro-to-programming">
<h1>Intro To Programming</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Intro to Programming</div>
<p class="text-smaller"><b>Q:</b> What is a program?</p>
<p class="fragment text-smaller pad-left-lg">⇒ Set of instructions that tells a computer how to do a task</p>
<p class="text-smaller fragment"><b>Q:</b> What is programming?</p>
<p class="fragment text-smaller pad-left-lg">⇒ Writing instructions in a way the computer understands</p>
<p class="text-smaller fragment"><b>Q:</b> How do I become a programmer?</p>
<p class="fragment text-smaller pad-left-lg">⇒ Learning how to "think" like a computer</p>
</section>
<section class="center">
<h1>Introducing: Chandler-bot</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Think like a CPU - What did we learn?</div>
<p>• You have to speak the same language</p>
<p class="fragment">• Steps execute sequentially</p>
<p class="fragment">• Steps need to be granular and precise</p>
<p class="fragment">• The computer will only do what you tell it to do</p>
<p class="fragment">• The computer is never wrong</p>
</section>
<section class="title" id="pseudo-code">
<h1>Pseudo Code</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Pseudo Code</div>
<div class="text-smaller">
<p class="fragment">• Process of thinking through a program, step-by-step</p>
<p class="fragment">• No actual code is written</p>
<p class="fragment">• End result is an outline that can be converted into code</p>
<p class="fragment">• Allows you to focus on <u>problem solving</u>, not the layout of the code and its syntax</p>
<p class="fragment">• Don't need to know how to code, to write pseudo code!</p>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Pseudo Code</div>
<p>• Let's write pseudo code for a thermostat:</p>
<p class="pad-left-lg text-smaller">User inputs a temperature, if the current temperature is colder, turn the heat on, otherwise turn the heat off</p>
<div class="fragment">
<p>• Things to think about:</p>
<div class="pad-left-lg text-smaller">
<p>⇒ What are the <u>inputs</u> for our program?</p>
<p>⇒ What is the desired <u>output</u> of our program?</p>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Pseudo Code</div>
<div class="text-left text-smaller">
<div class="fragment">
<p><code>set target_temperature = 72</code></p>
</div>
<div class="fragment">
<p><code>get current_temperature = 68</code></p>
</div>
<div class="fragment">
<p><code>if current_temperature < target_temperature</code></p>
<p class="pad-left-lg"><code>turn_heater_up</code></p>
</div>
<div class="fragment">
<p><code>if current_temperature >= target_temperature</code></p>
<p class="pad-left-lg"><code>turn_heater_off</code></p>
</div>
</div>
</section>
<section class="title" id="working-with-js">
<h1>Working Locally With JS</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Working Locally with JavaScript</div>
<div class="text-smallest">
<p>• JavaScript files use the <code class="code">.js</code> extension - <code class="code">script.js</code></p>
<div class="fragment">
<p>• Two methods to link HTML and JS:</p>
<p class="pad-left-lg">⇒ External (as a separate file):</p>
<pre><code>
<script type="text/javascript" src="script.js"></script>
</code></pre>
<p class="pad-left-lg">⇒ Locally (in our HTML):</p>
<pre><code>
<script type="text/javascript">
// Write JavaScript here
</script>
</body>
</code></pre>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Code Along: First JavaScript</div>
<div class="text-left text-smallest">
<p>1. Open <code class="code">first-javascript</code> directory in SublimeText</p>
<p>2. Add the following to <code class="code">index.html</code>, above <code class="code"></body></code></p>
<pre><code>
<script type="text/javascript" src="script.js"></script>
</code></pre>
<p>3. Add the following to <code class="code">script.js</code></p>
<pre><code>
alert('This is an alert. This is annoying');
</code></pre>
<p>4. Save and open <code class="code">index.html</code> in the browser</p>
</div>
</section>
<section class="center">
<h1>Let's take a Break</h1>
<img src="img/main/break-time-bear.jpg">
</section>
<!-- JAVASCRIPT BASICS -->
<section class="title" id="js-basics">
<h1>JavaScript Basics</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaSript Basics: Data Types</div>
<div class="text-smaller">
<p>• In the machine, there is only data</p>
<p class="fragment">• Data are separated by type:</p>
<div class="pad-left-lg text-smaller">
<p class="fragment">⇒ Numbers: <code class="code">1</code>, <code class="code">2</code>, <code class="code">100</code></p>
<p class="fragment">⇒ Strings: <code class="code">"cats"</code>, <code class="code">"i love javascript"</code></p>
<p class="fragment">⇒ Booleans: <code class="code">true</code> and <code class="code">false</code></p>
<p class="fragment">⇒ Objects: <code class="code">{ name: "Keanu Reeves" }</code></p>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Data Types: Numbers</div>
<p>• Used for arithmetic: (operators: <code class="code">+</code>, <code class="code">-</code>, <code class="code">*</code>, <code class="code">/</code> )</p>
<div class="pad-left-lg">
<p><code class="code">2 + 2</code>, <code class="code">5 - 2</code>, <code class="code">8 * 20</code>, <code class="code">100 / 2</code></p>
</div>
<div class="fragment">
<p>• Advanced operations contained in the <code class="code">Math</code> library:</p>
<div class="pad-left-lg">
<p>⇒ <code class="code">Math.pow(2,3)</code> = 8</p>
<p>⇒ <code class="code">Math.sqrt(25)</code> = 5</p>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Data Types: Strings</div>
<div class="text-smallest">
<p>• Used to represent text: <code class="code">"Hello, World!"</code></p>
<div class="fragment">
<p>• Notable for <b>string concatenation</b>:</p>
<pre><code>
'c' + 'a' + 't'
// "cat"
</code></pre>
</div>
<div class="fragment">
<p>• Can concatenate different data types (numbers, variables) with strings:</p>
<pre><code>
'i have ' + 2 + ' cats'
// "i have 2 cats"
</code></pre>
</div>
</div>
</section>
<!--
<section data-background="#FFF" class="text-left">
<div class="heading">Data Types: Strings</div>
<p>• ES6 introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" target="_blank">template strings</a></p>
<p>• A cleaner way to perform string concatenation:</p>
<pre><code>
var first = 'Barack'
var last = 'Obama'
`Your name is ${first} ${last}.`
// "Your name is Barack Obama"
</code></pre>
<p>• Note the tick marks surrounding the template: <code class="code">`</code></p>
</section> -->
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Code Along: First JavaScript</div>
<div class="text-left text-smallest">
<p>1. Reopen <code class="code">first-javascript</code> in SublimeText</p>
<p>2. Add the following <code class="code">document.write()</code> messages:</p>
<div class="pad-left-lg">
<p>• The product of 10 and 10:</p>
<pre><code>
document.write(10 * 10);
</code></pre>
<p>• The quotient of 100 and 10</p>
<p>• The difference of 50 and 17</p>
<p>• The sum of 50 and 17</p>
<p>• Your first and last name (using string concatenation)</p>
</div>
</div>
</section> -->
<section class="title">
<h1>JS Basics: Variables</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">JavaScript Basics: Variables</div>
<div class="text-smallest">
<p>• Often, you will want to keep track of data in a program</p>
<p class="fragment">• Declare using the <code class="code">var</code> keyword</p>
<p class="fragment">• Will store the piece of data in memory</p>
<div class="fragment">
<p>• Use the variable's name to "call" it (retrieve it from memory):</p>
<pre><code>
var x = 2;
var y = 3;
x
// 2
x + y
// 5
</code></pre>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Variables: Naming Rules</div>
<div class="text-smaller">
<p>• Take care when naming your variables!</p>
<p class="fragment">• Variable names should reflect the data they describe</p>
<div class="fragment">
<p>• Other naming conventions:</p>
<div class="pad-left-lg">
<p>⇒ Names should start with a lowercase letter</p>
<p>⇒ Cannot use spaces; use <b>camelCase</b>:</p>
<pre><code>
var currentTemp = 70;
var targetTemp = 73;
</code></pre>
</div>
</div>
</div>
</section>
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Variable: Reassignment</div>
<div class="text-smallest">
<p>1. Declare a variable, <code class="code">x</code>, and assign it to the number <code class="code">2</code></p>
<pre><code>
var x = 2;
</code></pre>
<div class="fragment">
<p>2. Perform any arithmetic method on <code class="code">x</code></p>
<pre><code>
x * 2
// 4
</code></pre>
</div>
<div class="fragment">
<p>3. What's <code class="code">x</code> now equal to?</p>
<pre><code>
x
// 2
</code></pre>
</div>
</div>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Variables: Reassignment</div>
<p><b>NOTE</b>: you must <u>reassign</u> variables to change them</p>
<pre><code>
var x = 2
x * 2
// 4
x
// 2
x = x * 2
// 4
x
// 4
</code></pre>
</section> -->
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Code Along: First JavaScript</div>
<p>1. Open <code class="code">first-javascript</code> in SublimeText</p>
<p>2. Store your previous arithmetic in variables:</p>
<pre><code>
var num1 = 10 * 10;
</code></pre>
<p>3. Use <code class="code">document.write()</code> with the variables:</p>
<pre><code>
document.write(num1);
</code></pre>
</section> -->
<section class="title" id="document-querying">
<h1>Document Querying</h1>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Document Querying</div>
<p>• Popular use case of JS is to "talk" to HTML/CSS</p>
<p class="fragment">• Browser creates <code class="code">document</code> to communicate with JS</p>
<p class="fragment">• Majority of FE work leverages this <code class="code">document</code></p>
<p class="fragment">• The Document Object Model (DOM)</p>
<p class="fragment">• Always start with the <code class="code">document</code>!</p>
</section>
<section data-background="#FFF" class="text-left">
<div class="heading">Document Querying</div>
<p><code class="code">document.querySelector('selector')</code></p>
<div class="pad-left-lg">
<p>⇒ Returns <u>first</u> element matching the <code class="code">selector</code></p>
<p class="fragment">⇒ Can query for elements, classes, and ID's</p>
</div>
<div class="fragment">
<pre><code>
document.querySelector('#some-id')
// returns the first element with id of "some-id"
document.querySelector('.some-class')
// returns the first element class of "some-class"
</code></pre>
</div>
</section>
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Document Querying</div>
<p><code class="code">document.querySelectorAll(selectors)</code></p>
<div class="pad-left-lg text-smallest">
<p>⇒ Returns a <u>list</u> of the elements within the document</p>
<p>⇒ Can query for elements, classes, and ID's</p>
</div>
<pre><code>
document.querySelectorAll('p')
// returns all <p> tags
document.querySelectorAll('.some-class')
// returns all elements with class of "some-class"
</code></pre>
</section> -->
<section data-background="#FFF" class="text-left">
<div class="heading">Lab: First JavaScript</div>
<div class="text-smallest">
<p>1. Open <code class="code">first-javascript</code> in SublimeText</p>
<p>2. Add the following elements to <code class="code">index.html</code>:</p>
<pre><code>
<h1 id="title">Some Title</h1>
<p id="text-chunk">A block of text! Yay! Content! SEO!</p>
</code></pre>
<p>3. Use a document query to target the above elements and change their text color</p>
<p class="pad-left-lg">Hint: combine your query with <code class="code">.style.color = 'red'</code></p>
</div>
</section>
<!-- THE END -->
<section class="center">
<img src="img/main/the-end.jpg">
</section>
<!-- HOMEWORK -->
<!-- <section data-background="#FFF" class="text-left">
<div class="heading">Homework</div>
<p>1. Complete <code class="code">startup-matchmaker</code></p>
<p>2. Attempt <a href="https://dash.generalassemb.ly/" target="_blank">Dash</a> projecs four and five</p>
<p>3. Final project deliverable one: project proposal(s)</p>
<p>4. Pre-reading</p>
</section> -->
<!-- ON DECK -->
<section data-background="#FFF" class="text-left">
<div class="heading">On Deck: #12 - Javascript and the Browser</div>
<p>• More JavaScript!</p>
<p>• Functions</p>
<p>• The DOM</p>
<p>• JavaScript events</p>
<p>• Getting Input/Writing Output</p>
</section>
<section class="center">
<h1>Exit Tickets!</h1>
</section>
</div>
</div>
<script src="js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>