forked from girldevelopit/gdi-featured-js-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass3.html
More file actions
420 lines (368 loc) · 15.4 KB
/
class3.html
File metadata and controls
420 lines (368 loc) · 15.4 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 3 - Intro to JavaScript - Girl Develop It</title>
<meta name="description" content="Girl Develop It framework for easily creating beautiful presentations using HTML in GDI theme. Forked from Hakim El Hattab's reveal.js">
<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.css">
<link rel="stylesheet" href="css/theme/simple.css" id="theme">
<link rel="stylesheet" href="css/custom.css">
<!-- For syntax highlighting -->
<!-- light editor --> <link rel="stylesheet" href="lib/css/light.css">
<!-- dark editor <link rel="stylesheet" href="lib/css/dark.css">-->
<!-- <link rel="stylesheet" href="lib/css/zenburn.css">-->
<link rel="stylesheet" href="plugin/accessibility-helper/css/accessibility-helper.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="css/print/pdf.css" type="text/css" media="print">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<img src="img/circle-gdi-logo.png" alt="BDI Logo" class="noborder" style="max-height:400px;">
<h1>Introduction to JavaScript</h1>
<h2>Class 3</h2>
</section>
<!-- Loops -->
<section id="loops">
<section>
<h3>Loops</h3>
<img src="img/hula-hoop.jpg" alt="Lego stormtrooper inside key ring"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/steve_pires/8430087504/" target="_blank">Steve Pires</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>While loops</h3>
<p>While will repeat the same code over and over until some condition is met.</p>
<pre class="js"><code>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>Make sure something changes in the loop, or your loop will go on forever...</p>
<img src="img/infinite-loop.jpg" alt="Spiral that goes on toward infinity"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/samueljohn/5348462863/" target="_blank">Samuel John</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>For loops</h3>
<p>For loops are very similar, but you declare a counter in the statement.</p>
<pre><code class="js">//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>You can add other statements or logical operators inside the loops.</p>
<pre><code class="js">//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>To exit a loop, use the break statement.</p>
<pre><code class="js">//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>Write a loop that gives you the 9's times table,<br /> from 9 x 1 = 9 to 9 x 12 = 108.</p>
<p>Finish early? Try using a loop inside a loop to write all the times tables, from 1 to 12.</p>
</section>
</section>
<!-- Arrays -->
<section id="arrays">
<section>
<h3>Arrays</h3>
<img src="img/kitten-group.jpg" alt="Group of kittens"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/pasotraspaso/4444291348/" target="_blank">Jesus Solana</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Arrays</h3>
<p>Arrays are ordered lists of values.</p>
<pre><code class="js">var arrayName = [element0, element1, ...];
</code></pre>
<p>You can put different types of data into an array.</p>
<pre><code class="js">var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green',
'Blue', 'Indigo', 'Violet'];
var lotteryNumbers = [33, 72, 64, 18, 17, 85];
var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
</code></pre>
</section>
<section>
<h3>Array Length</h3>
<p>The length property tells you how many things are in an array</p>
<pre><code class="js">var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green',
'Blue', 'Indigo', 'Violet'];
console.log(rainbowColors.length);
</code></pre>
</section>
<section>
<h3>Using Arrays</h3>
<p>You can access items with "bracket notation" by using the position of the object you want. Programmers start counting at zero.</p>
<pre><code class="js">var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green',
'Blue', 'Indigo', 'Violet'];
var firstColor = rainbowColors[0];
var lastColor = rainbowColors[6];
</code></pre>
</section>
<section>
<h3>Changing arrays</h3>
<p>You can use bracket notation to change an item in an array</p>
<pre><code class="js">var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
myFavoriteThings[0] = 'Asparagus';
</code></pre>
</section>
<section>
<h3>Expanding arrays</h3>
<p>Arrays do not have a fixed length. You can use "push" to add something to an array.</p>
<pre><code class="js">var myFavoriteThings = ['Broccoli', 1024, 'Sherlock'];
myFavoriteThings.push('Dancing');
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create an array of your favorite foods. Echo a few values onto your screen.</p>
</section>
</section>
<!-- Arrays and loops-->
<section id="arraysandloops">
<section>
<h3>Arrays + loops = BFF</h3>
<img src="img/holding-hands.jpg" alt="Couple holding hands"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/mtsofan/8221708017/" target="_blank">John</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Iterating through arrays</h3>
<p>Use a for loop to easily process each item in an array.</p>
<pre><code class="js">var rainbowColors = ['Red', 'Orange', 'Yellow', 'Green',
'Blue', 'Indigo', 'Violet'];
for (var i = 0; i < rainbowColors.length; i++) {
console.log(rainbowColors[i]);
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Use a loop to make a list of all your favorite foods.</p>
</section>
</section>
<!-- Objects -->
<section>
<section>
<h3>Objects</h3>
<img src="img/matches.jpg" alt="Collection of matches"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/8RnSsa">Jirí Volejník</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>Objects</h3>
<p>Objects let us store a collection of properties.</p>
<pre><code class="js">var objectName={
propertyName: propertyValue,
propertyName: propertyValue,
...
};
</code></pre>
<pre><code class="js">var aboutMe={
hometown: 'Atlanta, GA',
hair: 'Auburn',
likes: ['knitting', 'code'],
birthday: {month: 10, day: 17}
};
</code></pre>
</section>
<section>
<h3>Accessing Objects</h3>
<p>You can retrieve values using "dot notation"</p>
<pre><code class="js">var aboutMe={
hometown: 'Atlanta, GA',
hair: 'Auburn'
};
var myHometown=aboutMe.hometown;
</code></pre>
<p>Or using "bracket notation" (like arrays)</p>
<pre><code class="js">var myHair=aboutMe['hair'];
</code></pre>
</section>
<section>
<h3>Changing Objects</h3>
<p>You can use dot or bracket notation to change properties</p>
<pre><code class="js">var aboutMe={
hometown: 'Atlanta, GA',
hair: 'Auburn'
};
aboutMe.hair='blue';
</code></pre>
<p>Add new properties</p>
<pre><code class="js">aboutMe.gender='female';
</code></pre>
<p>Or delete them</p>
<pre><code class="js">delete aboutMe.gender;
</code></pre>
</section>
<section>
<h3>Arrays of Objects</h3>
<p>Because arrays can hold any data type, they can also hold objects</p>
<pre><code class="js">var myCats=[
{name: 'Lizzie', age: 18},
{name: 'Daemon', age: 1}
];
for (var i=0; i < myCats.length; i++) {
var myCat=myCats[i];
console.log(myCat.name + ' is ' + myCat.age + ' years old.');
}
</code></pre>
</section>
<section>
<h3>Arrays of Objects</h3>
<p>Just like other data types, objects can be passed into functions:</p>
<pre><code class="js">var lizzieTheCat={
age: 18,
furColor: 'grey',
likes: ['catnip', 'milk'],
birthday: {month: 7, day: 17, year: 1996}
}
function describeCat(cat) {
console.log('This cat is ' + cat.age + ' years old with '
+ cat.furColor + ' fur.');
}
describeCat(lizzieTheCat);
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create an object to hold information on your favorite recipe. It should have properties for recipeTitle (a string), servings (a number), and ingredients (an array of strings).</p>
<p>Try displaying some information about your recipe.</p>
<p>Bonus: Create a loop to list all the ingredients.</p>
</section>
</section>
<!-- Object Methods -->
<section>
<section>
<h3>Object methods</h3>
<p>Objects can also hold functions.</p>
<pre><code class="js">var lizzieTheCat={
age: 18,
furColor: 'grey',
meow: function() {
console.log('meowww');
},
eat: function(food) {
console.log('Yum, I love ' + food);
},
};
</code></pre>
<p>Call object methods using dot notation:</p>
<pre><code class="js">lizzieTheCat.meow();
lizzieTheCat.eat('brown mushy stuff');
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Go back to your recipe object. Add a function called letsEat that says "I'm hungry! Let's eat."</p>
<p>Call your new method.</p>
</section>
<section>
<h3>Built-in methods</h3>
<p>JS provides several built-in objects:</p>
<ul>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array">Array</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number">Number</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String">String</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp">RegExp</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date">Date</a></code></li>
<li><code><a target="_blank" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math">Math</a></code></li>
</ul>
</section>
</section>
<!-- Final slides-->
<section id="final">
<section>
<h3>You did it!</h3>
<img src="img/fireworks.jpg" alt="Fireworks"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/markwdw85/9425240584/" target="_blank">Mark W.</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Resources</h3>
<ul>
<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">Code Academy</a>, with interactive JavaScript lessons to help you review.</li>
</ul>
</section>
<section>
<h2>Questions?</h2>
</section>
</section>
</div>
<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>
</footer>
</div>
<script src="lib/js/head.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,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.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, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/accessibility-helper/js/accessibility-helper.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>