forked from girldevelopit/gdi-featured-js-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass1.html
529 lines (466 loc) · 21.1 KB
/
class1.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 1 - 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 1</h2>
</section>
<!-- Welcome -->
<section>
<section>
<h2>Welcome!</h2>
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<br />
<h4>Some "rules"</h4>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Have fun</li>
</ul>
</section>
<section>
<h2>Welcome!</h2>
<h4>Tell us about yourself.</h4>
<ul>
<li>Who are you?</li>
<li>What do you hope to get out of the class?</li>
<!-- Feel free to change the icebreaker question! -->
<li>What's your favorite ice cream flavor?</li>
</ul>
</section>
</section>
<!-- What is JavaScript-->
<section id="whatis">
<section>
<h3>JavaScript is NOT Java</h3>
<img src="img/not-java.png" alt="Java logo with a no symbol"/>
</section>
<section>
<h3>JavaScript is a client-side language</h3>
<img src="img/client-server.jpg" alt="Laptop and server connected via the internet"/>
<p class="credit">Photo credits: <a href="http://www.flickr.com/photos/papalars/5210226441/" target="_blank">Andrew E. Larson</a> and <a href="http://www.flickr.com/photos/johnseb/3425464/" target="_blank">John Seb Barber</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>JavaScript works with HTML and CSS</h3>
<img src="img/triangle.jpg" alt="Triangle"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/ggunson/44539990/">Gillicious</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>JavaScript lets you reuse code</h3>
<img src="img/desert-landscape.jpg" alt="Desert landscape"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/philsnyder/4216356826/" target="_blank">Phil Synder</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>What is JavaScript?</h3>
<ul>
<li>JavaScript is standardized by the "ECMAScript" specifications.</li>
<li>JavaScript is a client-side processing language. A browser reads the code and runs it directly.</li>
<li>JavaScript interfaces with HTML and CSS.</li>
<li>With JavaScript, you can write code once and use it everywhere. Remember, you want DRY code (Don't Repeat Yourself).</li>
<li>JavaScript lets you build dynamic webpages that respond to input from users.</li>
</ul>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Let's write your first JavaScript program. Make a folder called gdi. Inside, make a new page called index.html. Place this code inside.</p>
<pre><code class="html"><!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is my awesome JavaScript code.</p>
<script>
alert('Hello World!');
console.log ('Secret message');
</script>
</body>
</html>
</code></pre>
</section>
</section>
<!-- Programming -->
<section id="programming">
<section>
<h3>Computers need simple, clear instructions</h3>
<img src="img/confusedrobot.jpg" alt="Confused robot"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/baboon/3946055/" target="_blank">baboon</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Thinking like a programmer</h3>
<p>Computers are great at <em>processing</em>. They are bad at <em>understanding</em>.</p>
<p>When you write a program, you must break down every step into simple pieces.</p>
</section>
<section>
<h3>Example: Draw a Square</h3>
<ol class="fragment">
<li>Find a whiteboard and a dry erase marker</li>
<li>Uncap the dry erase maker</li>
<li>Hold the marker in your hand</li>
<li>Place the marker against the whiteboard</li>
<li>Move your hand 1 foot to the right</li>
<li>Stop</li>
<li>Move your hand 1 foot down...</li>
</ol>
</section>
<section>
<h3>Example: Make a Sandwich</h3>
<iframe title="Sandwich video" width="560" height="315" src="https://www.youtube.com/embed/XWe4iohhmIw" frameborder="0" allowfullscreen></iframe>
<p class="credit">Source: <a>Harvard Students Making Sandwich: CS 50 Algorithm Intro</a></p>
</section>
<section>
<h3>Basically, computers can be hard to work with!</h3>
<img src="img/computer-toddler.jpg" alt="Toddler using old word processor"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/5Uvapm" target="_blank">Dan Hatton</a> <a href="https://creativecommons.org/licenses/by-nc-nd/2.0/" target="_blank">cc</a></p>
<aside class="notes">Reassure the students! Coding is difficult, and it may take time to get good at it. Also, the natural state of code is broken. It's normal to have error messages, </aside>
</section>
</section>
<!-- JavaScript Basics -->
<section id="basics">
<section>
<h3>So what's up with JavaScript?</h3>
<img src="img/gears.jpg" alt="Gears"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/EEo4BV" target="_blank">Adam Foster</a> <a href="https://creativecommons.org/licenses/by-nc-nd/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>How does JavaScript work?</h3>
<ol>
<li>A user visits a webpage with JavaScript code on it.</li>
<li>The user's browser (e.g., Chrome) reads the code line-by-line.</li>
<li>The browser executes (runs) each line of code as it reads it.</li>
<li>Based on these instructions, the browser performs calculations and changes the HTML and CSS on the page.</li>
<li>If the browser finds code it doesn't understand, it stops running an creates an error message.</li>
</ol>
</section>
<section>
<h3>Watch Out!</h3>
<p>Every browser interprets JavaScript differently.</p>
<p>You can see what's going on in the console.</p>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Open the console. In Chrome or Firefox, use the keyboard shortcut <strong>Command + Option + J</strong> (Mac) or <strong>Control + Shift + J</strong> (Windows/Linux).</p>
<p>Open your practice page. Do you see anything in the console?</p>
<p>Try typing in 2 + 2</p>
</section>
</section>
<!-- Using JavaScript -->
<section id="usingJS">
<section>
<h3>Script Tags</h3>
<p>You can mix JavaScript and HTML. The script tag tells your browser the stuff inside is code, not content.</p>
<pre><code class="html"><script>
CODE GOES HERE
</script>
</code></pre>
</section>
<section>
<h3>JavaScript Files</h3>
<p>Just like CSS, you can split a long block of JavaScript into its own file. </p>
<pre><code class="html"><script src="path/to/file.js"></script>
</code></pre>
</section>
<section>
<h3>Separating Instructions</h3>
<p>After each individual statement, you must add a semicolon.</p>
<pre><code class="js">console.log('Hello World!');
console.log('I am glad to meet you');
console.log('I am fuzzy');
</code></pre>
</section>
<section>
<h3>Comments</h3>
<p>You can leave comments in your code—notes that people can read and computers will ignore.</p>
<pre><code class="js">/*I can make long comments
with multiple lines
like this*/
console.log('Hello World!'); //Or make short comments like this
</code></pre>
</section>
<section>
<h3>Getting results onto your screen</h3>
<p>Open a popup box.</p>
<pre><code class="js">alert('Hello World!');
</code></pre>
<p>Display a message in your console.</p>
<pre><code class="js">console.log('Hello World!');
</code></pre>
<p>Add something to the page.</p>
<pre><code class="js">document.write('Hello World!');
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Open index.html. Add a comment to the code.</li>
<li>Try different ways of printing your message.</li>
<li>Create a new file called mycode.js. Move your code to this file and link it to your page.</li>
</ul>
</section>
</section>
<!-- Variables -->
<section>
<section>
<h3>Variables</h3>
<p>A variable is a place to store values</p>
<img src="img/empty-glass.jpg" alt="Empty glass" class="noborder"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/giuliag/3570562404/" target="_blank">giulia gasparro</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Variable Values</h3>
<ul>
<li>When you first create a variable, it does not have a value (it is null).</li>
<li>You can set a value for a variable.</li>
<li>Variables can hold different types of information, like words, numbers, and collections of data.</li>
<li>The value of a variable can change over time.</li>
</ul>
</section>
<section>
<h3>Naming Variables</h3>
<ul>
<li>The variable name is case-sensitive.</li>
<li>A new variable needs to have a unique name.</li>
<li>Variable names need to start with a letter, $, or _.</li>
<li>Variable names can only be made of letters, numbers, $, or _.</li>
</ul>
</section>
<section>
<h3>Declaring a Variable</h3>
<p>To declare (create) a variable, just type the word "var" and the variable name.</p>
<pre><code class="js">var numberOfKittens;</code></pre>
<p>It is a good idea to give your variable a starting value. This is called initializing the variable.</p>
<pre><code class="js">var numberOfKittens = 5;</code></pre>
</section>
<section>
<h3>Using a Variable</h3>
<p>Once you have created a variable, you can use it in your code. Just type the name of the variable.</p>
<pre><code class="js">var numberOfKittens = 5;
console.log (numberOfKittens);
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>In your JS file, create a variable and give it a valid name and a value. Then, display the value.</p>
</section>
</section>
<!-- Variable Types and Operators-->
<!-- Numbers-->
<section>
<section>
<h3>Numbers!</h3>
<img src="img/kitten-basket.jpg" alt="Cats in a basket"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/tom-poes/2159348460/" target="_blank">WJ van den Eijkhof</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Numbers</h3>
<p>Variable can be numbers, either integers or floats (decimals).</p>
<pre><code class="js">var numberOfKittens = 5;
var cutenessRating = 9.6;
</code></pre>
<p>The browser will automatically convert integers to floats if needed</p>
</section>
<section>
<h3>Arithmetic Operators</h3>
<p>Once you have numbers, you can do math with them!</p>
<pre><code class="js">var numberOfKittens = 5;
var numberOfPuppies = 4;
var numberOfAnimals = numberOfKittens + numberOfPuppies;
</code></pre>
</section>
<section>
<h3>Arithmetic Operators</h3>
<table>
<thead>
<tr>
<th>Example</th>
<th>Name</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>-a</td>
<td>Negation</td>
<td>Opposite of a.</td>
</tr>
<tr>
<td>a + b</td>
<td>Addition</td>
<td>Sum of a and b.</td>
</tr>
<tr>
<td>a - b</td>
<td>Subtraction</td>
<td>Difference of a and b.</td>
</tr>
<tr>
<td>a * b</td>
<td>Multiplication</td>
<td>Product of a and b.</td>
</tr>
<tr>
<td>a / b</td>
<td>Division</td>
<td>Quotient of a and b.</td>
</tr>
<tr>
<td>a % b</td>
<td>Modulus</td>
<td>Remainder of a divided by b.</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create two variables and try some arithmetic operators. Don't forget to display your results!</p>
</section>
</section>
<!-- Strings -->
<section>
<section>
<h3>Strings</h3>
<p>Variable can be strings, groups of characters. You put your string in quotes.</p>
<pre><code class="js">var kittensName = 'Fluffy';</code></pre>
<p>If you want to use a quote in your string, you'll need to "escape" it with a backslash.</p>
<pre><code class="js">console.log('I\'d like to use an apostrophe');</code></pre>
</section>
<section>
<h3>Playing with Strings</h3>
<img src="img/kitten-string.jpg" alt="Cat playing with string"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/dirtbikedba/5796961878/" target="_blank">Mike Lawson</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>String Operators</h3>
<p>You can put strings together with a +, the concatenation operator.</p>
<pre><code class="js">var kittensName = 'Fluffy ';
var fullName = kittensName + 'McDougle';
console.log(fullName); //Outputs 'Fluffy McDougle'
</code></pre>
</section>
<section>
<h3>String Operators</h3>
<p>You can also use += to add things to the end of a string.</p>
<pre><code class="js">var kittensName = 'Admiral ';
kittensName += 'Snuggles';
console.log(kittensName); //Outputs 'Admiral Snuggles'
</code></pre>
</section>
<section>
<h3>Concatenate!</h3>
<img src="img/concatenate.jpg" alt="Cat jumping on another cat."/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/furlined/8191032061/" target="_blank">Matt</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create two variables, a first name and a last name, and then put them together to make a full name. Don't forget to display your results!</p>
</section>
</section>
<section>
<section>
<h3>Combining strings and numbers</h3>
<p>You can use the concatenate function to mix strings and numbers. When you do this, JavaScript will treat the number like a string.</p>
<pre><code class="js">var numberOfFruit = 6;
var typeOfFruit = 'bananas';
var allTheFruit = 'Wow, I have ' + numberOfFruit + ' ' + typeOfFruit + '!';
console.log(allTheFruit);
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create a program to calculate the tip at a restuarant. It should:</p>
<ul>
<li>Have variables for the bill pre-tip and the tip percentage</li>
<li>Calculate the total bill</li>
<li>Output a sentence like "Your total bill, with tip, is $14.75"</li>
</ul>
</section>
</section>
<!-- Final slides-->
<section id="final">
<section>
<h3>You did it!</h3>
<img src="img/celebration.jpg" alt="People celebrating"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/morphomir/2407451929/" target="_blank">Mircea</a> <a href="http://creativecommons.org/licenses/by-sa/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>
<li><a href="http://jsforcats.com/">JavaScript For Cats,</a> the basics of JavaScript explained with extra cats.</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>