forked from gdi-curriculum-review/gdi-featured-js-intro-OLD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class1.html
469 lines (431 loc) · 17 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 1 ~ JavaScript for Beginners ~ Girl Develop It</title>
<meta name="description" content="This is an introduction to JavaScript curriculum, developed by Sylvia Richardson for the Raleigh/Durham 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="reveal/css/reveal.css">
<link rel="stylesheet" href="reveal/css/theme/gdidefault.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="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" alt="GDI logo">
<h3>JavaScript for Beginners</h3>
<h4>Class 1</h4>
</section>
<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>
<section>
<h3>Welcome!</h3>
<div class = "left-align">
<p class = "blue">Tell us about yourself.</p>
<ul>
<li>Who are you?</li>
<li>What do you hope to get out of the class?</li>
<li>What is your favorite children's book?</li>
</ul>
</div>
</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>JavaScript is a client-side language</h3>
<img src="images/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>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>
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is my awesome JavaScript code.</p>
<script>
alert('Hello World!');
</script>
</body>
</html>
</code></pre>
</section>
<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>
<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>
<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>
<script>
console.log('Hello World!');
console.log('I am glad to meet you');
console.log('I am fuzzy');
</script>
</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>
<script>
/*I can wrap long comments
with multiple lines
like this*/
console.log('Hello World!'); //Or mark short comments like this
</script>
</code></pre>
</section>
<section>
<h3>Getting results onto your screen</h3>
<p>Open a popup box.</p>
<pre><code>
alert('Hello World!');
</code></pre>
<p>Display a message in your console.</p>
<pre><code>
console.log('Hello World!');
</code></pre>
<p>Add something to the page.</p>
<pre><code>
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>
<h3>Variables</h3>
<p>A variable is a place to store values</p>
</section>
<section>
<h3>Variable Values</h3>
<ul>
<li>When you first create a variable, it does not have a value (it is <em>undefined</em>).</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>
<script>
var numberOfKittens;
</script>
</code></pre>
<p>It is a good idea to give your variable a starting value. This is called initializing the variable.</p>
<pre><code>
<script>
var numberOfKittens = 5;
</script>
</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>
<script>
var numberOfKittens = 5;
console.log (numberOfKittens);
</script>
</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>
<h3>Numbers</h3>
<p>Variables can be numbers, either integers or floats (decimals).</p>
<pre><code>
<script>
var numberOfKittens = 5;
var cutenessRating = 9.6;
</script>
</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>
<script>
var numberOfKittens = 5;
var numberOfPuppies = 4;
var numberOfAnimals = numberOfKittens + numberOfPuppies;
</script>
</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>
<h3>Strings</h3>
<p>Variables can be strings, groups of characters. You put your string in quotes.</p>
<pre><code>
<script>
var kittensName = 'Fluffy';
</script>
</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>
<script>
console.log('I\'d like to use an apostrophe');
</script>
</code></pre>
</section>
<section>
<h3>String Operators</h3>
<p>You can put strings together with a +, the concatenation operator.</p>
<pre><code>
<script>
var kittensName = 'Fluffy ';
var fullName = kittensName + ' McDougle';
console.log(fullName); //Outputs 'Fluffy McDougle'
</script>
</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>
<script>
var kittensName = 'Admiral ';
kittensName += ' Snuggles';
console.log(kittensName); //Outputs 'Admiral Snuggles'
</script>
</code></pre>
</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>
<h3>Functions</h3>
<p>Functions are separable, reusable pieces of code.
</section>
<section>
<h3>Using Functions</h3>
<p>First, declare the function.</p>
<pre><code>
<script>
function turtleFact() {
console.log('A turtle\'s lower shell is called a plastron.');
}
</script>
</code></pre>
<p>Then, use it as many times as you want!</p>
<pre><code>
<script>
turtleFact();
</script>
</code></pre>
</section>
<section>
<h3>Arguments</h3>
<p>Functions can accept input values, called arguments.</p>
<pre><code>
<script>
function callKitten (kittenName){
console.log('Come here, ' + kittenName + '!');
}
callKitten ('Fluffy'); //outputs 'Come here, Fluffy!'
function addNumbers(a, b) {
console.log(a + b);
}
addNumbers(5,7); //outputs 12
addNumbers(9,12); //outputs 21
</script>
</code></pre>
</section>
<section>
<h3>Arguments</h3>
<p>You can also pass variables into functions. These variables do not need to have the same name as the function arguments.</p>
<pre><code>
<script>
function addOne(inputNumber){
var newNumber = inputNumber + 1;
console.log('<p>You now have ' + newNumber);
}
//Declare variables
var numberOfKittens = 5;
var numberOfPuppies = 4;
//Use them in functions
addOne(numberOfKittens);
addOne(numberOfPuppies);
</script>
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Turn the code you wrote to output someone's full name into a function, then use it.</p>
</section>
<section>
<h3>Returning Values</h3>
<p>You can have a function give you back a value, to use later.</p>
<pre><code>
<script>
function square(num) {
return num * num;
}
console.log(square(4)); // outputs '16'.
var squareOfFive = square(5); // will make squareOfFive equal 25.
</script>
</code></pre>
<p>Return will immediately end a function.</p>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Add a return statement to your name function. Use that function to set the value of a variable.</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">Codecademy</a>, with interactive JavaScript lessons to help you review.</li>
</ul>
</section>
</div><!-- Close .slides -->
<footer>
<div class="copyright">
JavaScript for Beginners ~ 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="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,
touch: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // 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>