-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-one.html
1081 lines (794 loc) · 34 KB
/
class-one.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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>GDI Mpls - Intermediate JavaScript</title>
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono:400,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/reveal.css">
<link rel="stylesheet" type="text/css" href="prism/prism.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/reveal.js"></script>
<script type="text/javascript" src="prism/prism.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div class="reveal" id="gdi">
<div class="slides">
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Introduction -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<section>
<h3 class="uppercase no_margin">Intermediate JavaScript</h3>
<div class="meta blue uppercase small_meta">06.04.18 ∙ GDI MPLS ∙ Amy Gebhardt</div>
<img src="img/gdi_logo_badge.png" class="top_margin width_50" style="width:30%;">
<div class="spacer"></div>
<div class="left_align" style="margin-top:-120px;">
<div class="meta white big_meta uppercase tiny_meta">Wifi</div>
<div class="meta gold tiny_meta">Network:
<span class="white">training</span>
</div>
<div class="meta gold tiny_meta">Password:
<span class="white">classroom</span>
</div>
<div class="meta gold tiny_meta">Slides:
<span class="white">https://gdiminneapolis.github.io/intermediate-js/class-one.html</span>
</div>
<div class="meta gold tiny_meta">Project Files:
<span class="white">https://tinyurl.com/yd9bo3y6</span>
</div>
</div>
</section>
<section>
<h3 class="no_margin navy">you belong here.</h3>
</section>
<section class="left_align">
<h3 class="uppercase no_margin gold">Welcome!</h3>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">Who are you?</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta white small_meta">What do you do?</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta white small_meta">How did you hear about Girl Develop It?</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta white small_meta">On a scale of 1 to "I could do this while sleeping" how comfortable are you with JavaScript and programming concepts?</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta white small_meta">What's a recent "win" you've had?</div>
</section>
<section class="left_align">
<h3 class="uppercase no_margin white">Expectations</h3>
<div class="spacer big_spacer"></div>
<div class="fragment meta pink small_meta">Review
<span class="fragment meta white tiny_meta">(today!)</span>
</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta pink small_meta">Vanilla JavaScript is ugly</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta pink small_meta">Define library and framework</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta pink small_meta">Learn how to research, implement, and use a library</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta pink small_meta">Hear what the "cool" kids are using these days</div>
<div class="spacer small_spacer"></div>
<div class="fragment meta pink small_meta">Do some cool stuff with jQuery</div>
<div class="spacer small_spacer"></div>
</section>
<section>
<h3 class="uppercase no_margin navy">get excited.</h3>
<div class="spacer small_spacer"></div>
<img src="img/excited.gif">
</section>
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Review - Part 1 -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<section>
<h1 class="uppercase no_margin gold">Review</h1>
</section>
<section>
<div class="spacer"></div>
<h3 class="no_margin blue">What is JavaScript?</h3>
<section>
<div id="server_graphic" class="fragment"></div>
<div class="fragment meta white">
<div class="spacer"></div>
<div class="spacer"></div>
A
<span class="gold">client-side</span>
<br />processing language.
</div>
<div class="spacer"></div>
<div class="fragment meta white">
The
<span class="gold">browser</span> reads
<br />and executes the code.
</div>
</section>
<section>
<div class="spacer"></div>
<div id="js_graphic" class="fragment"></div>
<div class="spacer"></div>
<div class="fragment meta white">
<div class="spacer"></div>
<div class="spacer"></div>
Works with
<span class="gold">HTML</span> and
<span class="gold">CSS</span>.
</div>
<div class="spacer"></div>
<div class="fragment meta white">Let's you build
<span class="gold">dynamic</span>
<br />web pages that respond
<br />to
<span class="gold">user input</span>.</div>
</section>
</section>
<section>
<h3 class="navy">Just like with CSS, you can put your JavaScript into separate files.</h3>
<h4 class="blue">JavaScript files have a
<span class="inline_code">.js</span> extension.</h4>
</section>
<section>
<h4 class="no_margin gold">Set up some project files:</h4>
<span class="spacer big_spacer"></span>
<div class="fragment meta white small_meta">
Download the project files by going to:
<span class="pink">https://tinyurl.com/yd9bo3y6</span>
</div>
<hr />
<div class="fragment meta white small_meta">
Unzip the
<span class="inline_code">intermediate-js-project-files.zip</span> file and move
<br/> the folder somewhere handy (in your repos
<br />folder, on your desktop, etc).
</div>
<hr />
<div class="fragment meta white small_meta">
Open your code editor, then open
<br /> your
<span class="inline_code">intermediate-js-project-files</span> directory.
</div>
</section>
<section>
<div class="fragment meta white small_meta">
Add a link to the
<span class="inline_code">scripts.js</span> file by modifying your
<span class="inline_code">index.html</span>.
<br />
<span class="tiny_meta">Don't forget to save!</span>
</div>
<div class="fragment skinny_pre" style="height:320px;">
<pre class="language-markup" data-src="src_samples/begin_index.html"></pre>
<div style="clear:both;"></div>
</div>
<hr>
<div class="fragment meta white small_meta">
Add this JavaScript to
<span class="inline_code">scripts.js</span> & save again:
</div>
<div class="fragment skinny_pre">
<pre class="language-markup" data-src="src_samples/begin_js.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="meta white small_meta">
Open
<span class="inline_code">index.html</span> in Google Chrome. What do you see?
</div>
</section>
<section class="highlighting_code_slide">
<h3 class="blue uppercase" style="font-size:39pt">So... what did we just do?</h3>
<h4 class="mono_font gray highlight_single_line_text">
document.write("JavaScript is awesome!");
</h4>
<!-- <h4 class="mono_font light_gray fragment highlight_single_line_text" data-fragment-index="1">
<span class="gold">document</span>.write("JavaScript is awesome!");
</h4>
<h4 class="mono_font light_gray fragment highlight_single_line_text" data-fragment-index="2">
document
<span class="gold">.</span>write("JavaScript is awesome!");
</h4>
<h4 class="mono_font light_gray fragment highlight_single_line_text" data-fragment-index="3">
document.
<span class="gold">write(</span>"JavaScript is awesome!"
<span class="gold">)</span>;
</h4>
<h4 class="mono_font light_gray fragment highlight_single_line_text" data-fragment-index="4">
document.write(
<span class="gold">"JavaScript is awesome!"</span>);
</h4>
<h4 class="mono_font light_gray fragment highlight_single_line_text" data-fragment-index="5">
document.write("JavaScript is awesome!")
<span class="gold">;</span>
</h4> -->
<div class="spacer big_spacer"></div>
<hr />
<div class="spacer big_spacer"></div>
<div class="fragment">
<div class="white meta small_meta">
We
<span class="gold">invoked</span> the
<span class="inline_code">write</span>
<span class="gold">function</span> on the
<span class="gold">global</span>
<span class="gold">object</span>:
<span class="inline_code">document</span>.
</div>
<hr />
<div class="meta white small_meta">
When we
<span class="gold">invoked</span> it, we gave it a
<span class="gold">parameter</span>
<br />of
<span class="gold">type</span>
<span class="gold">string</span>:
<span class="inline_code">"JavaScript is awesome!"</span>.
</div>
<hr />
<div class="meta white small_meta">
We ended the
<span class="gold">statement</span> with a
<span class="inline_code">;</span>.
</div>
</div>
</section>
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Review - Deep Dive (counter) -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - -->
<section>
<div id="ddr">
<div id="result">0</div>
<button id="ddr_subtract">-</button>
<button id="ddr_add">+</button>
</div>
</section>
<section>
<h4 class="no_margin gold">Let's try it!</h4>
<span class="spacer big_spacer"></span>
<div class="fragment meta white small_meta">
Go back to your
<span class="inline_code">index.html</span> file.
</div>
<hr />
<div class="fragment meta white small_meta">
Set up a few
<span class="gold">DOM</span> elements in the
<span class="inline_code"><body></span> of your page:
</div>
<div class="fragment skinny_pre" style="height:265px;">
<pre class="language-markup" data-src="src_samples/counter_dom.html"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta white">When you're ready, save and open the file in Chrome.</div>
</section>
<section>
<h4 class="no_margin gold">Let's try it!</h4>
<span class="spacer big_spacer"></span>
<div class="fragment meta white small_meta">
Add a link to the
<span class="inline_code">counter.css</span> file by modifying
<br />the
<span class="inline_code">head</span> of your
<span class="inline_code">index.html</span>.
</div>
<div class="fragment skinny_pre" style="height:170px;">
<pre class="language-markup" data-src="src_samples/add_counter_styles.html"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta white">When you're ready, save and open the file in Chrome.</div>
</section>
<section>
<h4 class="no_margin gold">Quick note...</h4>
<div class="spacer"></div>
<div class="fragment meta white small_meta">
This is not a CSS course, but it
<i>is</i> important to know when to use JavaScript and when to use CSS.
</div>
</section>
<section>
<h4 class="no_margin blue">Finally, onto the JavaScript!</h4>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
We need to
<span class="gold">select</span> the
<span class="inline_code">result</span>,
<span class="inline_code">subtract</span>, and
<span class="inline_code">add</span> elements.
</div>
<hr />
<div class="fragment meta white small_meta">
Store each element into a new
<span class="gold">variable</span>.
</div>
<hr />
<div class="fragment meta white small_meta">
To confirm you've successfully
<span class="gold">selected</span> them, output their
<span class="inline_code">innerHTML</span>
using
<span class="inline_code">document.write()</span>,
<span class="inline_code">alert()</span>, or
<span class="inline_code">console.log()</span>
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
We need to
<span class="gold">select</span> the
<span class="inline_code">result</span>,
<span class="inline_code">subtract</span>, and
<span class="inline_code">add</span> elements.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
Since these
<span class="gold">elements</span> are all accessible by an
<span class="inline_code">id</span>, we can use JavaScript's
<span class="inline_code">document.getElementById()</span> function.
</div>
<div class="fragment skinny_pre" style="height:150px;">
<pre class="language-markup" data-src="src_samples/counter_dom.html"></pre>
<!-- <div style="clear:both;"></div> -->
</div>
<div class="spacer"></div>
<div class="fragment skinny_pre">
<pre class="language-markup" data-src="src_samples/counter_get_element_by_id.js"></pre>
<!-- <div style="clear:both;"></div> -->
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
Store each element into a new
<span class="gold">variable</span>.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">The
<span class="gold">returned</span> value from each
<span class="inline_code">document.getElementById()</span> can
<br />be stored in a new
<span class="gold">variable</span> that we initialize using
<br />the
<span class="inline_code">var variableName = value;</span> syntax.
</div>
<div class="fragment skinny_pre" style="height:265px;">
<pre class="language-markup" data-src="src_samples/init_variables.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
To confirm you've successfully
<span class="gold">selected</span> them, output their
<span class="inline_code">innerHTML</span>
using
<span class="inline_code">document.write()</span> ,
<span class="inline_code">alert()</span> , or
<span class="inline_code">console.log()</span>
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">We'll access the
<span class="inline_code">innerHTML</span>
<span class="gold">property</span> from each of our new
<span class="gold">variables</span> using
<span class="gold">dot notation</span>.
</div>
<div class="fragment skinny_pre" style="height:80px;">
<pre class="language-markup" data-src="src_samples/dot_notation.js"></pre>
<div style="clear:both;"></div>
</div>
<hr />
<div class="fragment meta white small_meta">Using any of the three output methods,
<br />display the value of
<span class="inline_code">innerHTML</span>.
</div>
<div class="fragment" style="height:120px;">
<pre class="language-markup" data-src="src_samples/output_methods.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<h4 class="no_margin blue">Let's add some events!</h4>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
Next, we'll need to add an
<span class="gold">event listener</span> to handle the
<span class="inline_code">click</span>
event for the
<span class="inline_code">add</span> and
<span class="inline_code">subtract</span> buttons.
</div>
<hr />
<div class="fragment meta white small_meta">
To confirm you've successfully captured the
<span class="inline_code">click</span>
<span class="gold">event</span>, output a
<span class="inline_code">"hello world from the [add][subtract] click event!"</span>
message using
<span class="inline_code">document.write()</span>,
<span class="inline_code">alert()</span>, or
<span class="inline_code">console.log()</span>
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
Next, we'll need to add an
<span class="gold">event listener</span> to handle the
<br />
<span class="inline_code">click</span>
event for the
<span class="inline_code">add</span> and
<span class="inline_code">subtract</span> buttons.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">Use the
<span class="inline_code">addEventListener()</span> method on the
<span class="gold">Element
<br />object</span> using
<span class="gold">dot notation</span>
to capture the
<span class="inline_code">click</span>
<span class="gold">event</span>
<br />for both
<span class="inline_code">add</span>
and
<span class="inline_code">subtract.</span>
</div>
<div class="fragment skinny_pre" style="height:265px;">
<pre class="language-markup" data-src="src_samples/add_event_listener.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">
Next, we'll need to add an
<span class="gold">event listener</span> to handle the
<br />
<span class="inline_code">click</span>
event for the
<span class="inline_code">add</span> and
<span class="inline_code">subtract</span> buttons.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">The
<span class="inline_code">addEventListener()</span> method takes in two
<span class="gold">arguments</span>.
<br />The first is a
<span class="gold">string</span> and refers to the name of the event.
<br />In this case,
<span class="inline_code">"click"</span>.
</div>
<hr />
<div class="fragment meta white small_meta">The second
<span class="gold">argument</span> is a
<span class="gold">function</span> that is
<br />
<span class="gold">invoked</span> when the
<span class="gold">event</span> is triggered.
</div>
<div class="fragment skinny_pre" style="height:265px;">
<pre class="language-markup" data-src="src_samples/add_event_listener_with_arguments.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
To confirm you've successfully captured the
<span class="inline_code">click</span>
<span class="gold">event</span>, output a
<span class="inline_code">"hello world from the [add][subtract] click event!"</span>
message using
<span class="inline_code">document.write()</span>,
<span class="inline_code">alert()</span>, or
<span class="inline_code">console.log()</span>
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">Using any of the three methods, display the message.
<br />Make them unique, so you can see the difference
<br />between
<span class="inline_code">add</span> and
<span class="inline_code">subtract</span>.
</div>
<div class="fragment skinny_pre" style="height:185px;">
<pre class="language-markup" data-src="src_samples/display_event_listener_results.js"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment tiny_meta meta white">Open in Chrome to confirm the results!</div>
</section>
<section>
<h4 class="no_margin blue">Update the result</h4>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
Get the current
<span class="gold">content</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span>.
</div>
<hr />
<div class="fragment meta white small_meta">
Using JavaScript
<span class="gold">operators</span>, do the assumed operation (+1 if it's add, -1 if it's subtract) each time the
<span class="gold">buttons</span> are clicked.
</div>
<hr />
<div class="fragment meta white small_meta">
Update the
<span class="inline_code">HTML</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span>, so
<br />the user can see what's happening.
</div>
<hr />
<div class="fragment meta white small_meta">
Test your work!
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
Get the current
<span class="gold">content</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span>.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
We can get this by accessing the
<span class="inline_code">innerHTML</span> property
<br />on the
<span class="gold">Element object</span> using
<span class="gold">dot notation</span>. Let's go ahead
<br /> and store it in a new
<span class="gold">variable</span>.
</div>
<div class="fragment skinny_pre" style="height:185px;">
<pre class="language-markup" data-src="src_samples/save_current_value.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="fragment meta white tiny_meta task_quote">
Using JavaScript
<span class="gold">operators</span>, do the assumed operation (+1 if it's add, -1 if it's subtract) each time the
<span class="gold">buttons</span> are clicked.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
This snippet is for the
<span class="inline_code">add</span> button, so we'll add 1 to the
<span class="inline_code">currentResult</span>
<span class="gold">variable</span> and store that in a
<span class="inline_code">newResult</span>
<span class="gold">variable</span>.
</div>
<div class="fragment skinny_pre" style="height:185px;">
<pre class="language-markup" data-src="src_samples/add_one.js"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta blue">
Full disclosure: I'm intentionally leading you astray, here...
</div>
<div class="fragment meta tiny_meta white">
Output the value of
<span class="inline_code">newResult</span>. Is it what you expect?
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">
Using JavaScript
<span class="gold">operators</span>, do the assumed operation (+1 if it's add, -1 if it's subtract) each time the
<span class="gold">buttons</span> are clicked.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
JavaScript
<span class="gold">operators</span> behave differently depending
<br />on the
<span class="gold">data types</span>
being used.
</div>
<hr />
<div class="fragment meta white small_meta">
We need to convert the
<span class="gold">string</span> from
<span class="inline_code">innerHTML</span> to an
<span class="gold">integer</span> using JavaScript's
<span class="inline_code">parseInt()</span> function before we add or subtract 1 from it.
</div>
<div class="fragment skinny_pre" style="height:185px;">
<pre class="language-markup" data-src="src_samples/add_one_correct.js"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta white">
Output the value of
<span class="inline_code">newResult</span>. Is it what you expect?
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">
Update the
<span class="inline_code">HTML</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span> so the user can see what's happening.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
In addition to
<span class="gold">accessing</span> the
<span class="inline_code">innerHTML</span>
<span class="gold">property</span>,
<br />we can also
<span class="gold">set</span> it. The
<span class="gold">DOM</span> will be manipulated.
</div>
<div class="fragment skinny_pre" style="height:225px;">
<pre class="language-markup" data-src="src_samples/set_inner_html.js"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta white">
Open your page in Chrome. Test out both buttons. How'd we do?
</div>
</section>
<section>
<div id="ddr2">
<div id="result2">0</div>
<button id="ddr_subtract2">-</button>
<button id="ddr_add2">+</button>
</div>
</section>
<section>
<h4 class="no_margin gold">Quick note...</h4>
<div class="spacer"></div>
<div class="fragment meta white small_meta">
This is not a CSS course, but it
<i>is</i> important to know when to use JavaScript and when to use CSS.
</div>
</section>
<section>
<h4 class="no_margin blue">Style the result when it changes</h4>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
Set the
<span class="gold">class</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span> to
<span class="inline_code">"changing"</span> when either button is clicked.
</div>
<hr />
<div class="fragment meta white small_meta">
After
<span class="inline_code">200</span> milliseconds, remove the
<span class="gold">class</span>.
<br />
<span class="fragment meta blue tiny_meta">
CSS will handle all of the fancy transitions
<br />(and CSS typically does this better than JavaScript) </span>
</div>
<hr />
<div class="fragment meta white small_meta">
Test your work!
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">
Set the
<span class="gold">class</span> of the
<span class="inline_code">result</span>
<span class="gold">element</span> to
<span class="inline_code">"changing"</span> when either button is clicked.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
The
<span class="gold">Element object</span> also has a
<span class="inline_code">className</span>
<span class="gold">property</span>.
<br />Just like with
<span class="inline_code">innerHTML</span>, we can
<span class="gold">set</span> it and the
<br />
<span class="gold">DOM</span> will be manipulated.
</div>
<div class="fragment skinny_pre" style="height:95px;">
<pre class="language-markup" data-src="src_samples/add_class.js"></pre>
<div style="clear:both;"></div>
</div>
<div class="fragment meta tiny_meta white">
Open your page in Chrome. Test out both buttons.
<br />Did the class get added? How can you tell?
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">
After
<span class="inline_code">200</span> milliseconds, remove the
<span class="gold">class</span>.
</div>
<div class="spacer big_spacer"></div>
<div class="spacer big_spacer"></div>
<div class="fragment meta white small_meta">
We can use JavaScript's
<span class="inline_code">setTimeout()</span>
<span class="gold">function</span> to handle the
<span class="inline_code">200</span> millisecond delay.
</div>
<hr />
<div class="fragment meta white small_meta">
<span class="inline_code">setTimeout()</span> takes two
<span class="gold">arguments</span>. The first is a
<span class="gold">function</span> that is
<span class="gold">invoked</span> after the specified number of milliseconds. The number milliseconds is the second
<span class="gold">argument</span>.
</div>
<div class="fragment" style="height:215px;">
<pre class="language-markup" data-src="src_samples/using_timeout.js"></pre>
<div style="clear:both;"></div>
</div>
</section>
<section>
<div class="meta white tiny_meta task_quote">