forked from gdi-curriculum-review/gdi-jquery-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class2.html
553 lines (504 loc) · 20.4 KB
/
class2.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 2 ~ Javascript ~ Girl Develop IT</title>
<meta name="description" content="This is the official Girl Develop It Core Intro Javascript course. Material based on original material by Sara Chipps, Pamela Fox, Alexis Goldstein, Izzy Johnston and Leo Newball.
The course is meant to be taught in 4 two-hour sections. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="reveal/css/reveal.css">
<link rel="stylesheet" href="reveal/css/theme/gdidefault.css" id="theme">
<!-- For syntax highlighting -->
<!-- light editor<link rel="stylesheet" href="lib/css/light.css">-->
<!-- dark editor--><link rel="stylesheet" href="reveal/lib/css/dark.css">
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="reveal/css/print/pdf.css" type="text/css" media="print">
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening slide -->
<section>
<img src = "images/gdi_logo_badge.png">
<h3>Beginning Javascript</h3>
<h4>Class 2</h4>
</section>
<!-- Welcome-->
<section>
<h3>Welcome!</h3>
<div class = "left-align">
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<p class ="green">Some "rules"</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Have fun</li>
</ul>
</div>
</section>
<!-- Loops-->
<section>
<h3>Loops</h3>
<p>Sometimes you want to go through a piece of code multiple times</p>
<p class = "fragment">Why?</p>
<ul>
<li class = "fragment">Showing a timer count down</li>
<li class = "fragment">Displaying the results of a search</li>
<li class = "fragment">Adding images to a slideshow</li>
</ul>
</section>
<section>
<h3>The while loop</h3>
<p>The while loop tells JS to repeat statements until a condition is true:</p>
<pre><code contenteditable class = "javascript">
while (expression) {
// statements to repeat
}
</code></pre>
<pre><code contenteditable class = "javascript">
var x = 0;
while (x < 5) {
console.log(x);
x++;
}
</code></pre>
<div class = "fragment">
Review: '++' means increment by 1!
</div>
<div class = "fragment">
<div class = "yellow">Danger!!</div>
<p>What happens if we forget x++;?</p>
<p>The loop will never end!!</p>
</div>
</section>
<section>
<h3>The for loop</h3>
<p>The for loop is a safer way of looping</p>
<pre><code contenteditable class = "javascript">
for (initialize; condition; update) {
// statements to repeat
}
</code></pre>
<pre><code contenteditable class = "javascript">
for (var i = 0; i < 5; i++) {
console.log(i);
}
</code></pre>
<div class = "fragment">
Less danger of an infinite loop. All conditions are at the top!
</div>
</section>
<!-- Arrays -->
<section>
<h3>Array</h3>
<p>An array is a data-type that holds an ordered list of values, of any type:</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var arrayName = [element0, element1, ...];
</code></pre>
</div>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet'];
var favoriteNumbers = [16, 27, 88];
var luckyThings = ['Rainbows', 7, 'Horseshoes'];
</code></pre>
</div>
<div class = "fragment">
The length property reports the size of the array:
<pre><code contenteditable class = "javascript">
console.log(rainbowColors.length);
</code></pre>
</div>
</section>
<section>
<h3>Arrays -- returning values</h3>
<p class = "fragment">You can access items with "bracket notation".</p>
<div class = "fragment">
The number inside the brackets is called an "index"
<pre><code contenteditable class = "javascript">
var arrayItem = arrayName[indexNum];
</code></pre>
</div>
<div class = "fragment">
Arrays in JavaScript are "zero-indexed", which means we start counting from zero.
<pre><code contenteditable class = "javascript">
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet'];
var firstColor = rainbowColors[0];
var lastColor = rainbowColors[6];
</code></pre>
</div>
</section>
<section>
<h3>Arrays -- updating values</h3>
<div class = "fragment">
You can also use bracket notation to change the item in an array:
<pre><code contenteditable class = "javascript">
var awesomeAnimals = ['Corgis', 'Otters', 'Octopi'];
awesomeAnimals[0] = 'Bunnies';
</code></pre>
</div>
<div class = "fragment">
Or to add to an array:
<pre><code contenteditable class = "javascript">
awesomeAnimals[4] = 'Corgis';
</code></pre>
</div>
<div class = "fragment">
You can also use the push method:
<pre><code contenteditable class = "javascript">
awesomeAnimals.push('Ocelots');
</code></pre>
</div>
</section>
<section>
<h3>Loops and Arrays</h3>
Use a for loop to easily look at each item in an array:
<pre><code contenteditable class = "javascript">
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet'];
for (var i = 0; i < rainbowColors.length; i++) {
console.log(rainbowColors[i]);
}
</code></pre>
</section>
<!-- Exercise -->
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Add a new link to the exercise from last week</li>
<li>Add an onclick to the link for a function called favoriteThings()</li>
<li>Create a new function called favoriteThings() in the javascript file</li>
<li>In the function, create an array and loop through the results</li>
<li>Post the results in an alert "My favorite things are XX, YY, ZZ'</li>
<li>Bonus -- add an 'and' in the sentence before the last item</li>
</ul>
</section>
<!-- Objects-->
<section>
<h3>Objects</h3>
<p>Objects are a data type that let us store a collection of properties and methods.</p>
<pre><code contenteditable class = "javascript">
var objectName = {
propertyName: propertyValue,
propertyName: propertyValue,
...
};
</code></pre>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var charlie = {
age: 8,
name: "Charlie Brown",
likes: ["baseball", "The little red-haired girl"],
pet: "Snoopy"
};
</code></pre>
</div>
</section>
<section>
<h3>Objects -- returning values</h3>
<p>Access values of "properties" using "dot notation":</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var charlie = {
age: 8,
name: "Charlie Brown",
likes: ["baseball", "The little red-haired girl"],
pet: "Snoopy"
};
</code></pre>
</div>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var pet = charlie.pet;
</code></pre>
</div>
</section>
<section>
<h3>Objects -- returning values</h3>
<div class = "fragment">
Or using "bracket notation" (like arrays):
<pre><code contenteditable class = "javascript">
var name = charlie['name'];
</code></pre>
</div>
<div class = "fragment">
Non-existent properties will return undefined:
<pre><code contenteditable class = "javascript">
var gender = charlie.gender
</code></pre>
</div>
</section>
<section>
<h3>Objects -- changing values</h3>
<p>Use dot or bracket notation with the assignment operator to change objects.</p>
<div class = "fragment">
Change existing properties:
<pre><code contenteditable class = "javascript">
charlie.name = "Chuck";
</code></pre>
</div>
<div class = "fragment">
Or add new properties:
<pre><code contenteditable class = "javascript">
charlie.gender = "male";
</code></pre>
</div>
<div class ="fragment">
You can also delete properties:
<pre><code contenteditable class = "javascript">
delete charlie.gender;
</code></pre>
</div>
</section>
<section>
<h3>Arrays of Objects</h3>
<p>Arrays can hold objects too!</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var peanuts = [
{name: "Charlie Brown",
pet: "Snoopy"},
{name: "Linus van Pelt",
pet: "Blue Blanket"}
];
</code></pre>
</div>
<div class = "fragment">
That means we can use a for loop!
<pre><code contenteditable class = "javascript">
for (var i = 0; i < peanuts.length; i++) {
var peanut = peanuts[i];
console.log(peanut.name + ' has a pet named ' + peanut.pet + '.');
}
</code></pre>
</div>
</section>
<section>
<h3>Objects in functions</h3>
<p>You can pass an object into a function as a parameter</p>
<pre><code contenteditable class = "javascript">
var peanut ={
name: "Charlie Brown",
pet: "Snoopy"
};
</code></pre>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
function describeCharacter(character){
console.log(character.name + ' has a pet named ' + character.pet + '.');
}
</code></pre>
</div>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
describeCharacter(peanut);
</code></pre>
</div>
</section>
<!-- Exercise -->
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Add another link that calls the function myFriends() onclick</li>
<li>Add a new function to the javascript myFriends</li>
<li>In the function, create an array of friends objects, with their names and hair colors</li>
<li>Use a for loop to go through each friend and describe them</li>
<li>Alert the results</li>
<li>Bonus -- make a separate functions that describe the friends</li>
</ul>
</section>
<!-- DOM -->
<section>
<h3>DOM</h3>
<ul>
<li class = "fragment">"Document Object Model"</li>
<li class = "fragment">A way to interact with the HTML elements on a webpage</li>
<li class = "fragment">Chrome and Firefox -- Right click --> Inspect Element</li>
</ul>
<img src = "images/dom.png" class = "fragment">
</section>
<section>
<h3>DOM Interaction</h3>
<p class = "fragment">On every webpage, the document object gives us ways of accessing and changing the DOM.</p>
<p class = "fragment left-align">Every DOM "node" has properties. They are connected like a family tree.</p>
<p class = "fragment left-align"> Parent (parentNode), children (childNodes, firstChild), siblings (prevSibling, nextSibling)</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var bodyNode = document.body; // <body>
var htmlNode = document.body.parentNode; // <html>
for (var i = 0; i < document.body.childNodes.length; i++) {
var childNode = document.body.childNodes[i];
//could be <p>, <h1>, etc.
//any html element
}
</code></pre>
</div>
</section>
<section>
<h3>DOM Interaction: Easier</h3>
<p class = "fragment blue">Finding every element on the page by siblings and children is time consuming!</p>
<p class = "fragment">The document object also provides methods for finding DOM nodes without going one by one</p>
<div class = "fragment">
Find element by id
<pre><code contenteditable class = "html">
<img id="mainpicture" src="http://girldevelopit.com/assets/pink-logo.png">
</code></pre>
<pre><code contenteditable class = "javascript">
var img = document.getElementById('mainpicture');
</code></pre>
</div>
</section>
<section>
<h3>DOM Interaction: Easier</h3>
<div class = "fragment">
Find element by tag name (p, li, div, etc.)
<pre><code contenteditable class = "html">
<li class="peanut">Charlie Brown</li>
<li class="peanut">Linus van Pelt</li>
</code></pre>
<pre><code contenteditable class = "javascript">
var listItems = document.getElementsByTagName('li');
for (var i =0; i < listItems.length; i++) {
var listItem = listItems[i];
}
</code></pre>
</div>
</section>
<!-- Methods-->
<section>
<h3>Methods</h3>
<ul>
<li class = "fragment">Methods are functions that are associated with an object</li>
<li class = "fragment">The affect or return a value for a specific object</li>
<li class = "fragment">Used with dot notation</li>
</ul>
<div class = "fragment">
Previously seen example:
<pre><code contenteditable class = "javascript">
var img = document.getElementById('mainpicture');
</code></pre>
</div>
</section>
<!-- Attributes-->
<section>
<h3>DOM Nodes -- Attributes</h3>
<p>We can use node methods to set and retrieve attributes</p>
<div class = "fragment">
getAttribute/setAttribute
<pre><code contenteditable class = "javascript">
var img = document.getElementById('mainpicture');
img.getAttribute('src');
img.setAttribute('src', 'http://girldevelopit.com/assets/pink-logo.png');
</code></pre>
<pre><code contenteditable class = "javascript">
var img = document.getElementById('mainpicture');
img.getAttribute('class');
img.setAttribute('class', 'picture-class');
</code></pre>
</div>
</section>
<!-- Inner HTML-->
<section>
<h3>DOM innerHTML</h3>
<p>Each DOM node has an innerHTML property:</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
document.body.innerHTML;
</code></pre>
</div>
<div class = "fragment">
You can set innerHTML yourself to change the contents of the node:
<pre><code contenteditable class = "javascript">
document.body.innerHTML = '<p>I changed the whole page!</p>';
</code></pre>
</div>
<div class = "fragment">
You can also just add to the innerHTML instead of replace everything:
<pre><code contenteditable class = "javascript">
document.body.innerHTML += "...just adding this bit at the end of the page.";
</code></pre>
</div>
</section>
<!-- Create element and append child-->
<section>
<h3>DOM Modifying</h3>
<p>The document object can create new nodes:</p>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
document.createElement(tagName);
document.createTextNode(text);
document.appendChild();
</code></pre>
</div>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var newImg = document.createElement('img');
newImg.src = 'http://girldevelopit.com/assets/pink-logo.png';
document.body.appendChild(newImg);
</code></pre>
</div>
<div class = "fragment">
<pre><code contenteditable class = "javascript">
var newParagraph = document.createElement('p');
var paragraphText = document.createTextNode('New Paragraph!');
newParagraph.appendChild(paragraphText);
document.body.appendChild(newParagraph);
</code></pre>
</div>
</section>
<!-- Exercise-->
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Put it all together</li>
<li>Modify your existing three functions to add new elements to the screen instead of fire an alert</li>
<li>Keep in mind how to find an element, how to append an element, and how to change the inner html of an element</li>
<li>There are lots of possible solutions! Be creative!</li>
</ul>
</section>
<!-- -->
<section>
<h2>Questions?</h2>
<div style = "font-size:1200%; height:100%; margin-top:40%" class ="blue">?
<div class ="clear"></div></div>
</section>
</div>
<footer>
<div class="copyright">
Javascript ~ Girl Develop It ~
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="reveal/lib/js/head.min.js"></script>
<script src="reveal/js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal/plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'reveal/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>