forked from girldevelopit/gdi-featured-js-intro
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass4.html
668 lines (561 loc) · 28.2 KB
/
class4.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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 4 - 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="dist/css/reveal.css">
<link rel="stylesheet" href="dist/css/default.css" id="theme">
<!-- For syntax highlighting -->
<!-- light editor --> <link rel="stylesheet" href="dist/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 = 'dist/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="dist/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="dist/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<img src="dist/img/circle-gdi-logo.png" alt="GDI Logo" class="noborder" style="max-height:400px;">
<h1>Introduction to JavaScript</h1>
<h2>Class 4</h2>
</section>
<!-- Review: Role of HTML v. CSS-->
<section>
<h3>Let's Review</h3>
<img src="dist/img/elephants.jpg" alt="Two elephants interacting"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/ginable/325235488/">Ginable</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>Anatomy of a Website</h3>
<p><strong>Your Content</strong><br />
<strong>+ HTML</strong>: Structure<br />
<strong>+ CSS</strong>: Presentation<br />
<strong>= Your Website</strong></p>
<p>A website is a way to present your content to the world, using HTML and CSS to present that content & make it look good.</p>
</section>
<section>
<h3>HTML is Markup</h3>
<img src="dist/img/markup.jpg" alt="Printed document covered in ink marks"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/nics_events/2349630241/">Nic's events</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>CSS is Style</h3>
<img src="dist/img/fingernails.jpg" alt="Fingernails with polka-dot paint job"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/pumpkincat210/4778025555/">pumpkincat210</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>IDs vs Classes</h3>
<p><strong>ID</strong> - Should only apply to one element on a webpage, i.e., you might have an id of <code>banner</code> on your webpage's banner.<br />
The <code>#</code> is how you find ids in CSS.</p><br>
<p><strong>Class</strong> - Lots of elements can have the same class, i.e., There can be many elements with a <code>warning</code> class on one webpage.<br />
The <code>.</code> is how you find classes in CSS.</p>
</section>
<!--The DOM-->
<section>
<h3>Nesting</h3>
<p>HTML elements "nest" inside one another</p>
<img src="dist/img/nesting-dolls.jpg" alt="Russian nesting dolls"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/johnkay/3539939004/">John K</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>The DOM Tree: Sample Code</h3>
<p>Oftentimes, people think of HTML as something flat -- a bunch of text with tags in the middle. </p>
<pre><code class="html"><!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
<style>
h1 {
color: red;
}
</style>
</head>
<body>
<h1>My Page</h1>
<p>Hello World!</p>
<img src="http://placekitten.com/g/200/300" alt="cat"/>
</body>
</html>
</code></pre>
</section>
<section>
<h3>The DOM Tree: Sample Model</h3>
<p>However, it is something much more than that. Any HTML document is a tree structure defined by the <strong><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction">DOM (Document Object Model)</a></strong>.</p>
<img src="dist/img/dom-tree.png" alt="Simple DOM Tree"/>
</section>
<!--Accessing the DOM-->
<section>
<h3>DOM Access</h3>
<p>Your browser automatically loads the content of a webpage into a <code>Document</code> object which serves as the entry point into a web page's content.</p><br>
<p><strong>Using the <code>document</code> you can:</strong></p>
<ol>
<li>Change the content tree any way you want.</li>
<li>Build an HTML document from scratch.</li>
<li>Access or replace any existing DOM nodes (HTML elements in the DOM).</li>
</ol>
</section>
<section>
<h3>Finding Nodes</h3>
<img src="dist/img/search.jpg" alt="A magnifying glass"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/4UokrH">Jeffery Beall</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>DOM Access: By Id</h3>
<p>You can find nodes by <code>id</code> using the method:</p>
<pre><code class="javascript">document.getElementById(id);
</code></pre>
<p>For example, to find:</p>
<pre><code class="html"><img id="kittenPic" src="http://placekitten.com/g/200/300" alt="cat"/>
</code></pre>
<p>We would use:</p>
<pre><code class="javascript">var imgKitten = document.getElementById('kittenPic');
</code></pre>
</section>
<section>
<h3>DOM Access: By Tag Name</h3>
<p>You can also get HTML elements by their <code>tag</code> using this method:</p>
<pre><code class="javascript">document.getElementsByTagName(tagName);
</code></pre>
<p>To find:</p>
<pre><code class="html"><ul>
<li>Daisy</li>
<li>Tulip</li>
</ul></code></pre>
<p>We would use:</p>
<pre><code class="javascript">var listItems = document.getElementsByTagName('li');
for (var i = 0; i < listItems.length; i++) {
var listItem = listItems[i];
}
</code></pre>
</section>
<section>
<h3>DOM Access: HTML 5</h3>
<p>In newer browsers, you can use methods <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName">getElementsByClassName</a></code>, <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector">querySelector</a></code>, and <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll">querySelectorAll</a></code>.</p><br>
<p>Available in <a href="http://caniuse.com/#search=getElementsByClassName">IE9+, FF3.6+, Chrome 17+, Safari 5+</a>:</p>
<pre><code class="javascript">document.getElementsByClassName(className);
</code></pre><br>
<p>Available in <a href="http://caniuse.com/#search=querySelectorAll">IE8+, FF3.6+, Chrome 17+, Safari 5+</a>:</p>
<pre><code class="javascript">document.querySelector(cssQuery);
document.querySelectorAll(cssQuery);
</code></pre>
</section>
<section>
<h3>getElement vs. getElements</h3>
<p>Any method that starts with <code>getElement</code> will return a <strong>single</strong> node.</p>
<pre><code class="javascript">document.getElementById('uniqueID'); // returns a single node
</code></pre><br>
<p>Any method that starts with <code>getElements</code> will return an <strong>array</strong> of nodes. To modify a single node, you will need to use bracket notation to get the correct one.</p>
<pre><code class="javascript">document.getElementsByTagName('p'); // returns multiple nodes
var specificParagraph = document.getElementsByTagName('p')[2];
</code></pre>
</section>
<!--Manipulating the DOM-->
<section>
<h3>Changing Nodes</h3>
<img src="dist/img/two-color.jpg" alt="Red and yellow tulip"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/bCYp2S">Darryl Kenyon</a> <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">cc</a>
</section>
<section>
<h3>DOM Nodes: Attributes</h3>
<p>You can access and change attributes of DOM nodes using dot notation.</p><br>
<p>To change this element:</p>
<pre><code class="html"><img id="kittenPic" src="http://placekitten.com/g/200/300" alt="cat"/>
</code></pre>
<p>We could change the src attribute this way:</p>
<pre><code class="javascript">var imgKitten = document.getElementById('kittenPic');
// will return src attribute on image
imgKitten.src
// will set our src to a new src
imgKitten.src = 'http://placekitten.com/g/600/500';</code></pre>
</section>
<section>
<h3>DOM Nodes: Getting and Setting Attributes</h3>
<p>You can also use <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute">getAttribute</a></code> or <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute">setAttribute</a></code></p>
<pre><code class="html"><img id="kittenPic" src="http://placekitten.com/g/200/300" alt="cat"/>
</code></pre>
<p>We could change the src attribute this way:</p>
<pre><code class="javascript">var imgKitten = document.getElementById('kittenPic');
// will return src attribute on image
imgKitten.getAttribute('src');
// will set our src to a new src
imgKitten.setAttribute('src', 'http://placekitten.com/g/600/500');</code></pre>
</section>
<section>
<h3>DOM Nodes: Styles</h3>
<p>You can change page css using <code>style</code></p><br>
<p>To make this CSS:</p>
<pre><code class="css">body {
color: red;
}
</code></pre>
<p>Use this JavaScript:</p>
<pre><code class="javascript">var pageBody = document.getElementsByTagName('body')[0];
pageBody.style.color = 'red';</code></pre>
</section>
<section>
<h3>DOM Nodes: More Styles</h3>
<p>The rule of thumb in JavaScript is to change CSS styles with a "<code>-</code>" to <a href="https://en.wikipedia.org/wiki/CamelCase">camelCase</a>.</p><br>
<p>To make this CSS:</p>
<pre><code class="css">body {
background-color: pink;
padding-top: 10px;
}
</code></pre>
<p>Use this JavaScript:</p>
<pre><code class="javascript">var pageBody = document.getElementsByTagName('body')[0]
pageBody.style.backgroundColor = 'pink';
pageBody.style.paddingTop = '10px';
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create a simple HTML page or fork the pen at <a href="https://codepen.io/k80bowman/pen/WjjZBw">https://codepen.io/k80bowman/pen/WjjZBw</a>.</p>
<p>Isolate a node (an element on the page) and change an attribute or add a new style.</p>
</section>
<!--Manipulating the DOM-->
<section>
<h3>DOM innerHTML</h3>
<p>Each DOM node has an <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML">innerHTML</a></code> property with the HTML and content of its children. You can use the property to view or change the HTML of a node.</p><br>
<p>For example, you can overwrite the entire body:</p>
<pre><code class="javascript">var pageBody = document.getElementsByTagName('body')[0];
pageBody.innerHTML = '<h1>Oh Noes!</h1><p>I changed the whole page!</p>'</code></pre><br>
<p>Or just add some new content to the end</p>
<pre><code class="javascript">pageBody.innerHTML += '...just adding this at the end of the page.';</code></pre>
</section>
<section>
<h3>DOM innerHTML continued</h3>
<p>You can also target one specific element's content</p><br>
<p>To put content in this paragraph element:</p>
<pre><code class="html"><p id="warning"></p></code></pre>
<p>We can select the node and modify it</p>
<pre><code class="javascript">var warningParagraph = document.getElementById('warning');
warningParagraph.innerHTML = 'Danger Will Robinson!';</code></pre>
</section>
<section>
<h3>Creating New Nodes</h3>
<p>The <code>document</code> object also has methods to create nodes from scratch:</p>
<pre><code class="javascript">document.createElement(tagName);
document.createTextNode(text);
element.appendChild(element);</code></pre>
</section>
<section>
<h3>Creating New Nodes: Sample Code</h3>
<pre><code class="javascript">var pageBody = document.getElementsByTagName('body')[0];
// create our image tag with attributes
var newImg = document.createElement('img');
newImg.src = 'http://placekitten.com/g/500/200';
newImg.style.border = '1px solid black';
// add our image to the body
pageBody.appendChild(newImg);
// create a paragraph tag with content
var newParagraph = document.createElement('p');
var paragraphText = document.createTextNode('Squee!');
newParagraph.appendChild(paragraphText);
// add our new paragraph to the body
pageBody.appendChild(newParagraph);</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create a new paragraph element and add it to a <code>div</code> on your page.</p>
</section>
<!-- Events -->
<section>
<h3>Events</h3>
<img src="dist/img/magician.jpg" alt="Lego Magician" class="noborder"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/9hBrtv" target="_blank">Eva Peris</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Events</h3>
<p>An <strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events">event</a></strong> is an object that is sent when actions take place on your webpage, most often when a user interacts with your webpage.</p><br>
<p>For example, JavaScript creates an event when a user clicks an element.</p>
<pre><code class="javascript">element.addEventListener('click', function(event) {
// code to be executed when user clicks
});
</code></pre>
</section>
<section>
<h3>Types of Events</h3>
<p>There are a <a href="https://developer.mozilla.org/en-US/docs/Web/Events">variety of events</a>. Some of the more common events are:</p>
<ul>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/click">click</a>:</strong> Occurs when the user clicks on an element</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/mouseover">mouseover</a>:</strong> Occurs when the pointer is moved onto an element</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/mouseout">mouseout</a>:</strong> Occurs when the pointer is moved off an element</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/keyup">keyup</a>:</strong> Occurs when the user releases a key</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/load_(ProgressEvent)">load</a>:</strong> Occurs when a document has been loaded</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/focus">focus</a>:</strong> Occurs when an element gets focus</li>
<li><strong><a href="https://developer.mozilla.org/en-US/docs/Web/Events/blur">blur</a>:</strong> Occurs when an element loses focus</li>
</ul>
</section>
<section>
<h3>Calling Functions from HTML</h3>
<p>You can call a function directly from your HTML code:</p>
<pre><code class="html"><button id="myBtn" onclick="sayHi()">Click Me!</button>
</code></pre>
<pre><code class="javascript">function sayHi (event) {
alert('Hi!');
};</code></pre>
</section>
<section>
<h3>Calling Functions from JavaScript</h3>
<p>You can call a function from the addEventListener:</p>
<pre><code class="html"><button id="myBtn">Click Me!</button>
</code></pre>
<pre><code class="javascript">var button = document.getElementById("myBtn");
button.addEventListener("click", function (event) {
alert("Hi!");
});</code></pre>
<p>or</p>
<pre><code class="javascript">var button = document.getElementById("myBtn");
var sayHi = function (event) {
alert("Hi!");
};
button.addEventListener("click", sayHi);</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create a new pen on Codepen.</p>
<p>Add an HTML element.</p>
<p>Make some JavaScript code fire after a <code>mouseover</code> event on your element.</p>
</section>
<!-- More Events -->
<section>
<h3>Preventing Defaults</h3>
<img src="dist/img/donotwant.jpg" alt="A cat resisting a bath"/>
</section>
<section>
<h3>Preventing Defaults</h3>
<p>Elements like links and checkboxes have default behaviors determined by the browser. However, the <code>event</code> object has a built-in method to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault">prevent the default behavior</a></p>
<p>Our anchor link in HTML</p>
<pre><code class="html"><a id="myLink" href="https://www.girldevelopit.com">GDI</a>
</code></pre>
<p>Code to prevent going to link's href on click</p>
<pre><code class="javascript">var link = document.getElementById("myLink");
link.addEventListener("click", function(event) {
event.preventDefault();
});
</code></pre>
</section>
<section>
<h3>currentTarget</h3>
<img src="dist/img/arrow.jpg" alt="Lighted arrow sign pointed downward"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/6ei68A" target="_blank">Alan Berning</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>currentTarget</h3>
<p>The event's <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget">currentTarget</a></code> references the element the event listener was attached to.</p>
<p>Our button in HTML:</p>
<pre><code class="html"><button id="myBtn">Click Me!</a></code></pre>
<p>This code adds styles and text to our clicked button</p>
<pre><code class="javascript">myButton = document.getElementById("myBtn");
myButton.addEventListener("click", function(event) {
btn = event.currentTarget;
btn.style.backgroundColor = 'red';
btn.innerHTML = 'Clicked!';
};</code></pre>
<p>You may also see code that references the keyword <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this">this</a></code> as the "target".
</section>
<section>
<h3>Let's Develop It</h3>
<p>Write code that targets this link:</p>
<pre><code class="html"><a href="http://girldevelopit.com/" id="gdiLink">Girl Develop It</a>
</code></pre>
<p>When a user clicks the link, the page should display an error message instead of going to the Girl Develop It homepage.</p>
</section>
<!-- User input -->
<section>
<h3>User Input</h3>
<img src="dist/img/comment-box.jpg" alt="Comment box"/>
<p class="credit">Photo credit: <a href="https://flic.kr/p/fnZ4RT" target="_blank">Rym DeCoster</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></p>
</section>
<section>
<h3>Forms</h3>
<p>You can collect information from users to use in your code. The most common method is an HTML form</p>
<pre><code class="html"><form id="userForm">
<label for="name">First Name:</label>
<input type="text" id="firstName"/>
<input type="radio" name="married" value="Yes" checked /> Yes
<input type="radio" name="married" value="No" /> No
<input type="submit" id="submitBtn" value="Submit" />
</form>
</code></pre>
</section>
<section>
<h3>Retrieving Form Data</h3>
<p>You retrieve the values of form elements using the <code>value</code> method.</p>
<pre><code class="javascript">var name = document.getElementById('firstName').value;
console.log(name);
</code></pre>
<p>You can retrieve the value of a form at any time. Even when an event like <code>blur</code> is triggered (when a form element loses focus).</p>
</section>
<section>
<h3>Radio Buttons</h3>
<p>Radio buttons usually do not have IDs, so you will need to use a <code>for</code> loop to get the value on each radio:</p>
<pre><code class="javascript">var radios = document.getElementsByName('married');
var length = radios.length;
for (var i = 0; i < length; i++) {
if (radios[i].checked) {
var radioButtonValue = radios[i].value;
// only one radio can be checked, so stop now
break;
}
}
</code></pre>
</section>
<section>
<h3>Submit buttons</h3>
<p>If you are going to retrieve form values with the submit button, be sure to prevent the default action!</p>
<pre><code class="javascript">var submitButton = document.getElementById('submitBtn');
submitButton.addEventListener("click", function(event) {
event.preventDefault();
var name = document.getElementById('firstName').value;
console.log(name);
})
</code></pre>
</section>
<section>
<h2>Questions?</h2>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Collect a value from the input box on the page. Use it inside a function of some kind. For example, collect a number and multiply it by five or collect a name and display a greeting.</p>
</section>
<!-- Final slides-->
<section>
<h3>You did it!</h3>
<img src="dist/img/jumping-man.jpg" alt="Man jumping in air"/>
<p class="credit">Photo credit: <a href="http://www.flickr.com/photos/sunface13/988453859/" target="_blank">sunface13</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>
<li><a href="https://www.khanacademy.org/computing/cs/programming">Khan Academy</a> has a lot more information abut drawing and animations.</li>
<li><a href="https://www.freecodecamp.com/">Free Code Camp</a> has a great front-end development curriculum with lots of JavaScript.</li>
</ul>
</section>
<!-- ES6 stuff -->
<section>
<h2>Intro to ES6</h2>
</section>
<section>
<h3>Variables</h3>
<p>ES6 gives us a couple of different options for variables</p>
<ul>
<li><strong>const</strong>: Used when you don't want a variable to change</li>
<li><strong>let</strong>: Used when you might be re-using variable names</li>
</ul>
</section>
<section>
<h3>const</h3>
<pre><code class="javascript">const numberOfKittens = 0;
var numberOfPuppies = 0;
function addPuppies(numberOfNewPuppies) {
numberOfPuppies += numberOfNewPuppies;
return numberOfPuppies;
}
function addKittens(numberOfNewKittens) {
numberOfKittens += numberOfNewKittens;
return numberOfKittens;
}
function addTwoOfEach {
addPuppies(2);
addKittens(2);
document.write('I now have ' + numberOfPuppies + ' puppies and ' + numberOfKittens + ' kittens.');
}
</code></pre>
</section>
<section>
<h3>let</h3>
<pre><code class="javascript">let myFavoriteThings = [
'dogs',
'books',
'code'
];
function newFavoriteThings() {
let myFavoriteThings = [
'food',
'food',
'more food'
];
document.write(myFavoriteThings); //would print ['food', 'food', 'more food']
}
document.write(myFavoriteThings); //would print ['dogs', 'books', 'code']
</code></pre>
</section>
<section>
<h3>Template literals!</h3>
<p>Template literals are a super easy way to format output!</p>
<p>This:</p>
<pre><code class="javascript">var numberOfDogs = 6;
document.write('I have ' + numberOfDogs + ' dogs!');
</code></pre>
<p>Becomes this:</p>
<pre><code class="javascript">var numberOfDogs = 6;
document.write(`I have ${numberOfDogs} dogs!`);
</code></pre>
</section>
<section>
<h3>How does this work?</h3>
<p>Just like a document template, you leave spaces for things you expect people to fill in.</p>
<ul>
<li>surround your text in backticks instead of single quotes</li>
<li>surround your variables in ${}</li>
</ul>
</section>
<section>
<h2>Questions?</h2>
</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="dist/js/head.min.js"></script>
<script src="dist/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>