forked from gdi-curriculum-review/gdi-jquery-intro
-
Notifications
You must be signed in to change notification settings - Fork 2
/
class2.html
497 lines (451 loc) · 20.2 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Intro to JavaScript : Class 2 ~ Girl Develop It</title>
<meta name="description" content="This is an introduction to JavaScript curriculum, developed by Sylvia Richardson for the Raleigh/Durham chapter, modified by Julie Cameron and Sara Gibbons for the Ann Arbor chapter. 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="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/gdiaa.css" id="theme">
<link rel="stylesheet" href="lib/css/light.css">
<link rel="stylesheet" href="css/print/pdf.css" media="print">
<script src="lib/js/head.min.js"></script>
<!--[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">
<section>
<!-- Prep -->
<!-- <section>
<h3>Set Up Your Computer</h3>
<p class="box copy--small">Pull up <strong>these slides</strong>: <a href="http://bit.ly/gdiaa-js">bit.ly/gdiaa-js</a></p>
<p class="copy--small">Install <strong>Google Chrome</strong>, if you don't have it already.<br/><a href="http://google.com/chrome">google.com/chrome</a></p>
<p class="box copy--small">Install <strong>SublimeText,</strong> if you don't have it already.<br/><a href="http://sublimetext.com">sublimetext.com</a></p>
</section> -->
<!-- Opening slide -->
<section>
<img src="images/gdi_logo_badge.png" class="img--bare" height="450px" />
<div class="box--small">
<h3><span class="green">Intro to JavaScript</span></h3>
<h4><span class="blue">Class 2</span></h4>
</div>
</section>
<section>
<h3>Review</h3>
<p class="copy--small box--small">In this code, spot the comments, variables, operators, function, argument, and return value.</p>
<pre><code contenteditable>
function calculateTip(total) {
var tipPercent = 0.15; //Can be changed
return (total * tipPercent);
}
var billPreTip = 10;
var billTip = calculateTip(billPreTip);
var receipt = 'Meal: ' + billPreTip + ' Tip: ' + billTip +
' Total: ' + (billPreTip + billTip);
console.log(receipt);
</code></pre>
</section>
</section>
<section>
<section>
<h3>Variable Scope</h3>
<p class="copy--small box--small">The scope of a variable is how long the computer will remember it.</p>
</section>
<section>
<h3>Global Scope</h3>
<p class="copy--small box--small">A variable declared outside a function has a <span class="yellow">global</span> scope and can be accessed anywhere, even in a function.</p>
<pre><code contenteditable>
var awesomeGroup = 'Girl Develop It'; //Global scope
function whatIsAwesome() {
console.log(awesomeGroup + ' is pretty awesome.'); //Will work
}
whatIsAwesome();
</code></pre>
</section>
<section>
<h3>Local Scope</h3>
<p class="copy--small box--small">A variable declared within a function has a <span class="yellow">local</span> scope and can only be accessed within that function.</p>
<pre><code contenteditable>
function whatIsAwesome() {
var awesomeGroup = 'Girl Develop It'; //Local scope
console.log('I made a variable called awesomeGroup with a value of ' + awesomeGroup); //Will work
}
<!--on the slide, line 84 has a purple { and it's closing bracket } on line 87 is white. do they need to be the same color?-->
whatIsAwesome();
console.log(awesomeGroup + ' is pretty awesome.'); //Won't work
</code></pre>
</section>
<section>
<h3>Boolean Variables</h3>
<p class="copy--small box--small">Boolean variables represent the logical values True and False</p>
<pre><code contenteditable>
var catsAreBest = true;
var dogsRule = false;
</code></pre>
<p class="copy--small box--small">If you try to use another variable as a boolean, JavaScript will guess.<br/>The number <code contenteditable>0</code>, the empty string <code contenteditable>''</code>, <code contenteditable>undefined</code>, and <code contenteditable>null</code> are considered false, everything else reads as true.</p>
</section>
<section>
<h3>The if statement</h3>
<p class="copy--small box--small">Use if to decide which lines of code to execute, based on a condition.</p>
<pre style="height: 140px; overflow: hidden;"><code contenteditable>
if (condition) {
// statements to execute
}
</code></pre>
<pre style="height: 140px; overflow: hidden;"><code contenteditable>
var bananas = 5;
if (bananas > 0) {
console.log('You have some bananas!');
}
</code></pre>
</section>
<section>
<h3>Comparison Operators</h3>
<table class="copy--xsmall">
<thead>
<tr>
<th width="150px"><strong>Example</strong></th>
<th width="250px"><strong>Name</strong></th>
<th><strong>Result</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><code contenteditable>a == b</code></td>
<td>Equal</td>
<td><code contenteditable>true</code> if a is equal to b (can be different types).</td>
</tr>
<tr>
<td><code contenteditable>a === b</code></td>
<td>Identical</td>
<td>
<code contenteditable>true</code> if a is equal to b, and the same type. </td>
</tr>
<tr>
<td><code contenteditable>a != b</code></td>
<td>Not equal</td>
<td><code contenteditable>true</code> if a is not equal to b (can be different types).</td>
</tr>
<tr>
<td><code contenteditable>a !== b</code></td>
<td>Not identical</td>
<td>
<code contenteditable>true</code> if a is not equal to b, or they are not the same type.</td>
</tr>
<tr>
<td><code contenteditable>a < b</code></td>
<td>Less than</td>
<td><code contenteditable>true</code> if a is strictly less than b.</td>
</tr>
<tr>
<td><code contenteditable>a > b</code></td>
<td>Greater than</td>
<td><code contenteditable>true</code> if a is strictly greater than b.</td>
</tr>
<tr>
<td><code contenteditable>a <= b</code></td>
<td>Less than or equal to </td>
<td><code contenteditable>true</code> if a is less than or equal to b.</td>
</tr>
<tr>
<td><code contenteditable>a >= b</code></td>
<td>Greater than or equal to </td>
<td><code contenteditable>true</code> if a is greater than or equal to b.</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3>Watch out!</h3>
<p class="copy--small box--small">Don't mix up <code contenteditable>=</code> and <code contenteditable>==</code></p>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Make a variable called "temperature." Write some code that tells you to put on a coat if it is below 50 degrees.</p>
</section>
</section>
<section>
<section>
<h3>The if/else statement</h3>
<p class="copy--small box--small">Use else to provide an alternate set of instructions.</p>
<pre><code contenteditable>
var age = 28;
if (age >= 16) {
console.log('Yay, you can drive!');
} else {
console.log('Sorry, but you have ' + (16 - age) +
' years until you can drive.');
}
</code></pre>
</section>
<section>
<h3>The if/else if/else statement</h3>
<p class="copy--small box--small">If you have multiple conditions, you can use else if.</p>
<pre><code contenteditable>
var age = 20;
if (age >= 35) {
console.log('You can vote AND hold any place in government!');
} else if (age >= 25) {
console.log('You can vote AND run for the Senate!');
} else if (age >= 18) {
console.log('You can vote!');
} else {
console.log('You can\'t vote, but you can still write your representatives.');
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Modify your "wear a coat" code for these conditions:</p>
<ol class="copy--small box--small list--tall">
<li>If it is less than 50 degrees, wear a coat.</li>
<li>If it is less than 30 degrees, wear a coat and a hat.</li>
<li>If it is less than 0 degrees, stay inside.</li>
<li>Otherwise, wear whatever you want.</li>
</ol>
</section>
</section>
<section>
<section>
<h3>Logical Operators</h3>
<table class="copy--xsmall" style="width: auto; margin: 0 auto;">
<thead>
<tr>
<th width="200px">Example</th>
<th width="150px">Name</th>
<th width="300px">Result</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>a && b</code></td>
<td>And</td>
<td><code contenteditable>true</code> if both a and b are <code contenteditable>true</code>.</td>
</tr>
<tr>
<td><code>a || b</code></td>
<td>Or</td>
<td><code contenteditable>true</code> if either a or b is <code contenteditable>true</code>.</td>
</tr>
<tr>
<td><code>!a</code></td>
<td>Not</td>
<td><code contenteditable>true</code> if a is not <code contenteditable>true</code>.</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3>Using logical operators</h3>
<p class="copy--small box--small">You can use these operators to combine conditions.</p>
<pre><code contenteditable>
var bananas = 5;
if (bananas >=2 && bananas <7) {
console.log('You have a reasonable number of bananas');
} else {
console.log('Check your banana supply');
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Add a logical operator to your what to wear program.</p>
</section>
</section>
<section>
<section>
<h3>While loops</h3>
<p class="copy--small box--small">While will repeat the same code over and over<br/>until some condition is met.</p>
<pre><code contenteditable>
var bottlesOfBeer = 99;
while (bottlesOfBeer >= 1) {
console.log(bottlesOfBeer + ' bottles of beer on the wall');
bottlesOfBeer = bottlesOfBeer - 9;
}
</code></pre>
</section>
<section>
<h3>Infinite Loops</h3>
<p class="copy--small box--small">Make sure something changes in the loop, or your loop will go on forever...</p>
</section>
<section>
<h3>For loops</h3>
<p class="copy--small box--small">For loops are very similar, but you declare a counter in the statement.</p>
<pre><code contenteditable>
//will count 1 to 10
for (var i = 1; i <= 10; i++) {
console.log(i);
}
</code></pre>
</section>
<section>
<h3>Loops and logic</h3>
<p class="copy--small box--small">You can add other statements or logical operators inside the loops.</p>
<pre><code contenteditable>
//Count from 1 to 50
for (var i = 1; i <= 50; i++) {
console.log(i);
//Says 'Buzz' after multiples of three
if (i % 3 == 0) {
console.log('Buzz');
}
//Says 'Bang' after multiples of five
if (i % 5 == 0) {
console.log('Bang');
}
}
</code></pre>
</section>
<section>
<h3>Break</h3>
<p class="copy--small box--small">To exit a loop, use the break statement.</p>
<pre><code contenteditable>
//Count from 100 to 200
for (var i = 100; i <= 200; i++) {
console.log('Testing ' + i);
//Stop at the first multiple of 7
if (i % 7 == 0) {
console.log('Found it! ' + i);
break;
}
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Write a loop that gives you the 9's times table,<br /> from 9 x 1 = 9 to 9 x 12 = 108.</p>
<p class="copy--small box--small">Finish early? Try using a loop inside a loop to write all the times tables, from 1 to 12.</p>
</section>
</section>
<section>
<section>
<h3>Arrays</h3>
<p class="copy--small box--small">Arrays are ordered lists of values.</p>
<pre style="height: 160px; overflow: hidden;"><code contenteditable>
var arrayName = [element0, element1, ...];
</code></pre>
<p class="copy--small box--small">You can put different types of data into an array.</p>
<pre style="height: 160px; overflow: hidden;"><code contenteditable>
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple'];
var lotteryNumbers = [33, 72, 64, 18, 17, 85];
var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
</code></pre>
</section>
<section>
<h3>Array Length</h3>
<p class="copy--small box--small">The length property tells you how many things are in an array</p>
<pre><code contenteditable>
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple'];
console.log(rainbowColors.length);
</code></pre>
</section>
<section>
<h3>Using Arrays</h3>
<p class="copy--small box--small">You can access items with <i>"bracket notation"</i><br/>by using the position of the object you want.</p>
<p class="copy--small box--small">In JavaScript, you start counting at zero.</p>
<pre><code contenteditable>
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple'];
var firstColor = rainbowColors[0];
var lastColor = rainbowColors[5];
</code></pre>
</section>
<section>
<h3>Changing arrays</h3>
<p class="copy--small box--small">You can use bracket notation to change an item in an array</p>
<pre><code contenteditable>
var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
myFavoriteThings[0] = 'Asparagus';
</code></pre>
</section>
<section>
<h3>Expanding arrays</h3>
<p class="copy--small box--small">Arrays do not have a fixed length.<br/>You can use <code>push</code> to add something to an array.</p>
<pre><code contenteditable>
var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
myFavoriteThings.push('Dancing');
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Create an array of your favorite foods.<br/>Log a few values onto your screen.</p>
</section>
</section>
<section>
<section>
<h3>Iterating through arrays</h3>
<p class="copy--small box--small">Use a for loop to easily process each item in an array.</p>
<pre><code contenteditable>
var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple'];
for (var i = 0; i < rainbowColors.length; i++) {
console.log(rainbowColors[i]);
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p class="copy--small box--small">Use a loop to print out a list of all your favorite foods.</p>
</section>
</section>
<section>
<section>
<h3>Resources</h3>
<ul class="copy--small list--tall box--small">
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide" target="_blank">JavaScript Guide</a>, from the Mozilla Developers Network.</li>
<li><a href="http://www.codecademy.com/tracks/javascript" target="_blank">Codecademy</a>, with interactive JavaScript lessons to help you review.</li>
</ul>
</section>
<section>
<h3>Practice!</h3>
<div class="box">
<a href="homework.html#class2">Optional homework!!</a>
<p class="box"><a href="https://gdiaa.slack.com/messages/0416-javascript-wkshp/details/" target="_blank" class="roll"><span>#0416-javascript-wkshp</span></a></p>
<p><small>Not on Slack? <a target="_blank" href="http://bit.ly/gdiaa-slack" class="roll"><span data-title="bit.ly/gdiaa-slack">bit.ly/gdiaa-slack</span></a></small></p>
</div>
</section>
<section>
<img src="images/gdi_logo_badge.png" class="img--bare" height="450px" />
<div class="box--small">
<h3><span class="green">Intro to JavaScript</span></h3>
<h4><a href="class3.html"><span class="blue">Class 3 »</span></a></h4>
</div>
</section>
</section>
</div><!-- Close .slides -->
<footer>
<div class="copyright">
Intro to 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><!-- Close .copyright -->
</footer>
</div><!-- Close .reveal -->
<script src="js/jquery.min.js"></script>
<script src="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,
rollingLinks: 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: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>