forked from gdi-curriculum-review/gdi-jquery-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class1.html
1146 lines (1068 loc) · 38.3 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
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>
<meta charset="utf-8">
<title>Class 1 ~ Javascript ~ Girl Develop IT</title>
<meta name="description" content="This is the official Girl Develop It Core Intro Javascript course. Material based on original material by Sara Chipps, Pamela Fox, Alexis Goldstein, Izzy Johnston and Leo Newball.
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">
<!-- 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">
<section>
<h3>Download class materials</h3>
<p><a href="http://bit.ly/gdipgh-js-materials">http://bit.ly/gdipgh-js-materials</a></p>
<p>This includes the slides.</p>
<br/>
<h3>Online Slides</h3>
<p>You can also access the slides at <a href="http://bit.ly/gdipgh-js-slides">http://bit.ly/gdipgh-js-slides</a></p>
</section>
<!-- Opening slide -->
<section>
<img src = "images/gdi_logo_badge.png">
<h3>Beginning Javascript</h3>
<h4>Class 1</h4>
</section>
<!-- Welcome-->
<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 data-state="activity">
<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 dinosaur?</li>
</ul>
</div>
</section>
<section>
<h3>Goals for the class</h3>
<ul>
<li><strong>Week 1: Intro to JavaScript</strong></li>
<li>Week 2: More JavaScript & the DOM</li>
<li>Week 3: Intro to jQuery</li>
<li>Week 4: AJAX and APIs</li>
</ul>
</section>
<!-- Terms-->
<section>
<h3>Terms</h3>
<ul>
<li>
<div class = "green">Web design</div>
<div>The process of planning, structuring and creating a website</div>
</li>
<li>
<div class = "green">Web development</div>
<div>The process of programming dynamic web applications</div>
</li>
</ul>
</section>
<section>
<h3>Terms</h3>
<ul>
<li>
<div class = "green">Front end</div>
<div>The outwardly visible elements of a website or application.
<span class ="blue">(Javascript goes here!)</span></div>
</li>
<li>
<div class = "green">Back end</div>
<div>The inner workings and functionality of a website or application.</div>
</li>
</ul>
</section>
<!-- Nitty gritty 1 - Clients and servers -->
<section>
<h3>Clients and servers</h3>
<p>How your computer accesses websites</p>
<img src = "images/client-server.png"/>
<p class = "fragment">JavaScript is "client side"</p>
<p class = "fragment">Your browser understands it!</p>
</section>
<!-- History-->
<section>
<h3>History of JavaScript</h3>
<ul>
<li class = "fragment">Developed by Brendan Eich of Netscape in 1995</li>
<li class = "fragment">Standardized in 1997</li>
<li class = "fragment">Java -- Actually JavaScript has nothing to do with the language Java. Java was just the cool kid in town at the time</li>
<li class = "fragment">Script -- Instructions that a computer can run one line at a time</li>
</ul>
</section>
<!-- History-->
<section>
<h3>History of JavaScript</h3>
<ul>
<li class = "fragment">"AJAX" -- a way to communicate to servers was created in 2005</li>
<li class = "fragment">jQuery -- a super-popular JavaScript Library 2006</li>
<li class = "fragment">Node.js -- a way for JavaScript to perform back end functions in 2010</li>
<li class = "fragment">2012 -- spec for JavaScript "nearly" finished</li>
</ul>
</section>
<!--What does JavaScript do -->
<section>
<h3>What does JavaScript do?</h3>
<ul>
<li><a href = "http://leandrovieira.com/projects/jquery/lightbox/" target = '_blank'>Image Galleries and Lightboxes</a></li>
<li><a href = "https://www.google.com/doodles/30th-anniversary-of-pac-man" target = '_blank'>Games and all sorts of Google Doodles</a></li>
<li><a href = "http://www.girldevelopit.com/materials" target = '_blank'>Interactions, like show/hide and accordians</a></li>
<li><a href = "http://www.girldevelopit.com/classes" target = '_blank'>Retrieving data from other websites (through APIs)</a></li>
<li>All sorts of awesomeness, including this slideshow!</li>
</ul>
</section>
<section>
<h3>Useful References</h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/JavaScript">Mozilla Developer Network - JavaScript</a></li>
<li><a href="http://www.w3.org/standards/webdesign/script">W3C JavaScript Specifications</a></li>
</ul>
</section>
<section data-state="activity">
<section>
<h3>Activity: Enhance a Web Site <br/>Using JavaScript</h3>
<p>Use JavaScript to add content and interactivity <br/>to a web site</p>
</section>
<section>
<h3>You will need</h3>
<ul>
<li>
Files for the activity (included in <a href="#">class materials</a>)
</li>
<li>
A modern browser (we recommend <a href="https://www.google.com/intl/en/chrome/browser/">Chrome</a>)
</li>
<li>
A text editor (we recommend <a href="http://www.sublimetext.com/">Sublime Text</a>)
</li>
</ul>
</section>
<section>
<h3>Open the files in your text editor</h3>
<p>The project can be found in the <code>activity</code> folder.</p>
<img src="images/text-editor.png"/>
</section>
<section>
<h3>Open the page in your browser</h3>
<p>Open <code>index.html</code>.</p>
<img src="images/browser.png"/>
</section>
</section>
<!--Statements -->
<section>
<h3>Statements/Script</h3>
<div>
<p>Each line in JavaScript is an instruction or a script.</p>
<p>When the browser reads it, it "executes the script".</p>
</div>
<pre><code contenteditable class ="javascript">
alert('Hello World!');
</code></pre>
<p class="fragment">Statements usually end with a semicolon</p>
</section>
<section data-state="activity">
<p>Try it out using the console.</p>
<img src="images/console_hello_world.png" />
</section>
<section>
<pre><code contenteditable class ="javascript">
alert('Hello World!');
</code></pre>
<p class="fragment"><strong>alert</strong> displays a message in an alert box</p>
<p class="fragment">Useful for notifying your user about an important event.</p>
<p class="fragment">Use sparingly!</p>
</section>
<section data-state="activity">
<p>Let's try another one!</p>
<pre><code contenteditable class ="javascript">
console.log('Hello World!');
</code></pre>
<p class="fragment"><strong>console.log</strong> outputs a message to the web console</p>
<div class="fragment">
<p>This is very useful for debugging</p>
<button style="font-size: 30px;"
onclick="console.log('You clicked the button ' + Date());">Click Me</button>
</div>
</section>
<section>
<h2>Adding JS to HTML</h2>
<p>Three main ways, just like CSS</p>
</section>
<section>
<h3>Adding JS to HTML: Inline</h3>
<pre><code contenteditable class="html">
<html>
<head>
<title>My Site!</title>
</head>
<body>
My site!
<a href="#" onclick="alert('Hello World!');">click me</a>
</body>
</html>
</code></pre>
<p class="fragment">We'll talk more about this one later</p>
</section>
<section>
<h3>Adding JS to HTML: Embedded</h3>
<pre><code contenteditable class="html">
<html>
<head>
<title>My Site!</title>
<script>
alert("Hello World!");
</script>
</head>
<body>
My site!
</body>
</html>
</code></pre>
</section>
<section>
<h3>Adding JS to HTML: External</h3>
<pre><code contenteditable class="html">
<html>
<head>
<title>My Site!</title>
<script src="scripts.js"></script>
</head>
<body>
My site!
</body>
</html>
</code></pre>
<p>scripts.js</p>
<pre><code contenteditable class="javascript">
alert("Hello World!");
</code></pre>
<p class="fragment">This is usually the best way to add JavaScript.</p>
</section>
<!-- Exercise-->
<section data-state="activity">
<section>
<h3>Let's Develop It</h3>
<h4>Hello World</h4>
<ul>
<li>Create a new JavaScript file (a file that ends in .js)</li>
<li>Link it to your html file</li>
<li>Output "Hello World" in your JavaScript file</li>
</ul>
</section>
<section>
<h3>Let's Develop It</h3>
<code>index.html</code>
<pre><code class ="html">
<!DOCTYPE html>
<html>
<head>
<title>Jane Doe's Site!</title>
<link rel="stylesheet" href="style.css">
<script src="scripts.js"></script>
</head>
<body>
<img class="photo" src="photo.png">
<h1>Jane Doe</h1>
<p>Hi! My name is Jane Doe.</p>
</body>
</html>
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<code>scripts.js</code>
<pre><code class ="javascript">
alert("Hello World!");
</code></pre>
or
<pre><code class ="javascript">
console.log("Hello World");
</code></pre>
</section>
<section>
<h3>Example</h3>
<p>Are you done or really stuck?</p>
<p>Check out <a href="class1/01-hello-world/index.html">our example</a>.</p>
</section>
</section>
<!-- Data Types-->
<section>
<h2>Data Types</h2>
<p>Information (data) in JavaScript <br/>comes in different types.</p>
</section>
<section>
<h3>Data type: String</h3>
<p>A group of characters in quotes</p>
<div class="fragment">
<p>You can use double quotes</p>
<pre><code contenteditable class ="javascript">
console.log("Hello World");
</code></pre>
</div>
<div class="fragment">
<p>or single quotes</p>
<pre><code contenteditable class ="javascript">
console.log('Hello World!');
</code></pre>
</div>
</section>
<section>
<div>
Make sure your quotes match!
</div>
<img src="images/quote-mix-error.png"/>
</section>
<section>
<h3>Data type: Number</h3>
<div class="fragment">
<p>Integers</p>
<pre><code contenteditable class ="javascript">
console.log(2012);
</code></pre>
</div>
<div class="fragment">
<p>Decimals</p>
<pre><code contenteditable class ="javascript">
console.log(3.14);
</code></pre>
</div>
</section>
<section>
<h3>Data type: Boolean</h3>
<p>true or false</p>
<div class="fragment">
<pre><code contenteditable class ="javascript">
console.log(true);
</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class ="javascript">
console.log(false);
</code></pre>
</div>
<p class="fragment">true/false must be all lowercase</p>
</section>
<section>
<h3>Data type: Null</h3>
<p>A special keyword denoting an empty (null) value.</p>
<div class="fragment">
<pre><code contenteditable class ="javascript">
console.log(null);
</code></pre>
</div>
<p class="fragment">null must be all lowercase</p>
</section>
<!-- Variables-->
<section>
<h3>Variables</h3>
<div>
<p>Variables store information</p>
</div>
<div class = "fragment">
<p>Declare a variable (Give it a name)</p>
<pre><code contenteditable class ="javascript">
var bananas;
</code></pre>
</div>
<div class = "fragment">
<p>Initialize variable (Give it a value)</p>
<pre><code contenteditable class ="javascript">
bananas = 5;
</code></pre>
</div>
</section>
<section>
<h3>Variables</h3>
<div>
<p>Declare and initialize at the same time!</p>
<pre><code contenteditable class ="javascript">
var bananas = 5;
</code></pre>
</div>
<div class = "fragment">
<p>Change value of variable</p>
<pre><code contenteditable class ="javascript">
bananas = 4;
</code></pre>
<p>(I ate a banana)</p>
</div>
</section>
<!-- Naming rules-->
<section>
<h3>Naming rules</h3>
<div class = "fragment">
<p>Begin with a letter, _, or $</p>
<p>Contain letters, numbers, _ and $</p>
<pre><code contenteditable class ="javascript">
var hello;
var _hello;
var $hello;
var hello2;
</code></pre>
</div>
<div class = "fragment">
<p>Names are case sensitive</p>
<pre><code contenteditable class ="javascript">
var hello;
var Hello;
var heLLO;
</code></pre>
</div>
</section>
<section>
<h3>Naming conventions</h3>
<p>Most people use either</p>
<div class = "fragment">
<p>Snake case</p>
<pre><code contenteditable class ="javascript">
var hello;
var hello_world;
var first_name;
</code></pre>
</div>
<div class = "fragment">
<p>Camel case</p>
<pre><code contenteditable class ="javascript">
var hello;
var helloWorld;
var firstName;
</code></pre>
</div>
<p class="fragment">Stick with one for consistency</p>
</section>
<section>
<h3>Naming conventions</h3>
<p>Give variables meaningful names</p>
<div class="fragment">
<p>bad names</p>
<pre><code contenteditable class ="javascript">
var foo = 3.14;
var fn = "Julie";
var a = true;
</code></pre>
</div>
<div class="fragment">
<p>good names</p>
<pre><code contenteditable class ="javascript">
var pi = 3.14;
var firstName = "Julie";
var isAllowed = true;
</code></pre>
</div>
</section>
<section>
<h3>Data type: Undefined</h3>
<p>no value yet</p>
<div class="fragment">
<pre><code contenteditable class ="javascript">
var favoriteDinosaur;
</code></pre>
</div>
</section>
<section>
<h3>JS data types are "loosely typed"</h3>
<div class="left-align">
<p>You don't know the data type of a variable until you assign it.</p>
<p class="fragment">The type can change when it is assigned different values.</p>
</div>
<pre class="fragment"><code contenteditable class ="javascript">
var looseType; // I am undefined
looseType = 10; // I am a number
looseType = "hi!"; // I am a string
looseType = false; // I am a boolean
looseType = null; // I am null
</code></pre>
</section>
<section>
<h3>Comments</h3>
<p>Used to add hints, notes, suggestions, or warnings. <br/>
The browser will ignore them.</p>
<pre><code contenteditable class ="javascript">
// comment on one line
/* comment on
multiple lines
*/
</code></pre>
<div class="fragment">
<p>Warning: Other people can see them in the source.</p>
<pre><code contenteditable class ="javascript">
// My super-secret password is password1234
/* I hate my users so much!
I curse them!
*/
</code></pre>
</div>
</section>
<!-- Expressions -->
<section>
<h2>Arithmetic Expressions</h2>
<p>Math-y expressions!</p>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Addition (+)</h3>
<pre><code contenteditable class ="javascript">
var bananas = 5;
var oranges = 2;
var fruit = bananas + oranges;
</code></pre>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Subtraction (-)</h3>
<pre><code contenteditable class ="javascript">
var bananas = 5;
var people = 3;
var leftover_fruit = bananas - people;
</code></pre>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Multiplication (*)</h3>
<pre><code contenteditable class ="javascript">
var seconds_per_minute = 60;
var minutes_per_hour = 60;
var seconds_per_hour = seconds_per_minute * minutes_per_hour;
</code></pre>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Division (/)</h3>
<pre><code contenteditable class ="javascript">
var days_per_year = 365;
var days_per_week = 7;
var weeks_per_year = days_per_year / days_per_week;
</code></pre>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Modulus (%)</h3>
<p>Returns the integer remainder of <br/>dividing the two operands.</p>
<pre><code contenteditable class ="javascript">
var grapes = 37;
var people = 7;
var leftover = grapes % people;
</code></pre>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Increment (++)</h3>
<p>Increments the value by 1</p>
<div class="fragment">
<p>Postfix - returns the value before adding one.</p>
<pre><code contenteditable class ="javascript">
var current_hour = 8;
current_hour++; // Returns 8
current_hour; // Returns 9
</code></pre>
</div>
<div class="fragment">
<p>Prefix - returns the value after adding one.</p>
<pre><code contenteditable class ="javascript">
var current_hour = 8;
++current_hour; // Returns 9
current_hour; // Returns 9
</code></pre>
</div>
</section>
<section>
<h3>Arithmetic Expressions: <br/>Decrement (--)</h3>
<p>Decrease the value by 1</p>
<div class="fragment">
<p>Postfix - returns the value before subtracting one.</p>
<pre><code contenteditable class ="javascript">
var current_hour = 8;
current_hour--; // Returns 8
current_hour; // Returns 7
</code></pre>
</div>
<div class="fragment">
<p>Prefix - returns the value after subtracting one.</p>
<pre><code contenteditable class ="javascript">
var current_hour = 8;
--current_hour; // Returns 7
current_hour; // Returns 7
</code></pre>
</div>
</section>
<section>
<h2>String Expressions</h2>
<p>Word-y expressions!</p>
</section>
<section>
<h3>String Expressions: <br/>Concatenation (+)</h3>
<p>Combines strings together</p>
<pre><code contenteditable class ="javascript">
var phrase = "My name is ";
var name = "Pat";
var sentence = phrase + name + ".";
</code></pre>
<div class="fragment">
<p>Assign and concatenate (+=)</p>
<pre><code contenteditable class ="javascript">
var sentence = "My name is ";
sentence += "Jo";
sentence += " and I like " + "cats";
</code></pre>
</div>
</section>
<section>
<p>We also used + for addition.</p>
<p>What happens when we mix numbers and strings?</p>
<pre><code contenteditable class ="javascript">
var num = 5; // This is a number
var str = "10"; // This is a string
num + num; // 10
str + str; // "1010"
num + str; // ????
str + num; // ????
</code></pre>
</section>
<section>
<pre><code contenteditable class ="javascript">
var num = 5; // This is a number
var str = "10"; // This is a string
num + num; // 10
str + str; // "1010"
num + str; // "510"
str + num; // "105"
</code></pre>
<p class="fragment">Be careful when you mix data types. <br/>
You can get unexpected results.</p>
</section>
<section data-state="activity">
<section>
<h3>Let's Develop It</h3>
<h4>Favorite activity calculator</h4>
<p>How many times do you do something in a year?</p>
<ul>
<li>Store one of your favorite activities in a variable</li>
<li>Store the times you do it per month in a variable</li>
<li>Store the months in a year in a variable</li>
<li>Calculate how many times you do the activity per year using
math operations</li>
<li>Output the result in one alert that includes: the activity,
times you do it a month, and times you do it a year</li>
</ul>
</section>
<section>
<h3>Let's Develop It</h3>
<h4>Favorite activity calculator</h4>
<img src="images/activity-alert.png"></img>
</section>
<section>
<h3>Hints</h3>
<ul>
<li>timesPerYear = timesPerMonth * monthsPerYear</li>
<li>You will need string concatenation to create the result.</li>
<li>Creating extra variables may be helpful.</li>
</ul>
</section>
<section>
<h3>Example</h3>
<p>Are you done or really stuck?</p>
<p>Check out <a href="class1/02-favorite-activity/index.html">our example</a>.</p>
</section>
</section>
<!-- If statement-->
<section>
<h3>if statement</h3>
<p>Runs some JavaScript based on conditions</p>
<div class = "fragment">
<pre><code contenteditable class ="javascript">
if (conditions) {
// statement to execute
}
</code></pre>
<p>If the conditions evaluate as <strong>true</strong>, <br/>
the JavaScript inside the braces runs.</p>
</div>
<div class = "fragment">
<pre><code contenteditable class ="javascript">
var bananas = 1;
if (bananas < 2) {
console.log("You should buy more bananas!");
}
</code></pre>
</div>
<p class="fragment">What would happen if bananas was set to 3?</p>
</section>
<section>
<h3>block statement</h3>
<p>A group of statements deliniated by braces.</p>
<pre><code contenteditable class ="javascript">
{
console.log("statement 1");
console.log("statement 2");
console.log("statement 3");
}
</code></pre>
</section>
<!-- Comparison-->
<section>
<h2>Comparisons</h2>
<p>Compare the values and return a logical value (boolean) based on whether the comparison is true</p>
<div class="fragment">
<p>Frequently used in conditionals like if</p>
<pre><code contenteditable class ="javascript">
(bananas < 2)
</code></pre>
</div>
</section>
<section>
<h3>Comparison: Equal</h3>
<p>Returns true if the values are equal</p>
<pre><code contenteditable class ="javascript">
1 == 1; // true
1 == 2; // false
"this" == "this" // true
"this" == "that" // false
10 == "10" // ???
</code></pre>
<div class="fragment">
<p>Use strict equals to check the data type (recommended)</p>
<pre><code contenteditable class ="javascript">
1 === 1; // true
1 === 2; // false
"this" === "this" // true
"this" === "that" // false
10 === "10" // false
</code></pre>
</div>
</section>
<section>
<h3>Comparison: Equal</h3>
<p>Returns true if the values are equal</p>
<p class = "fragment green"> Don't confuse = (assign a value) <br/>with == or === (compare a value)</p>
</section>
<section>
<h3>Comparison: Not Equal</h3>
<p>Returns true if the values are not equal</p>
<pre><code contenteditable class ="javascript">
1 != 1; // false
1 != 2; // true
"this" != "this" // false
"this" != "that" // true
10 != "10" // false
</code></pre>
<div class="fragment">
<p>Use strict not equals to check the data type (recommended)</p>
<pre><code contenteditable class ="javascript">
1 !== 1; // false
1 !== 2; // true
"this" !== "this" // false
"this" !== "that" // true
10 !== "10" // true
</code></pre>
</div>
</section>
<section>
<h3>Comparison: Greater than</h3>
<pre><code contenteditable class ="javascript">
3 > 1; // true
2 > 4; // false
</code></pre>
<br/>
<div class="fragment">
<h3>Comparison: Greater than or equal</h3>
<pre><code contenteditable class ="javascript">
3 >= 1; // true
3 >= 3; // true
2 >= 4; // false
</code></pre>
</div>
</section>
<section>
<h3>Comparison: Less than</h3>
<pre><code contenteditable class ="javascript">
1 < 3; // true
4 < 2; // false
</code></pre>
<br/>
<div class="fragment">
<h3>Comparison: Less than or equal</h3>
<pre><code contenteditable class ="javascript">
1 <= 3; // true
3 <= 3; // true
4 <= 2; // false
</code></pre>
</div>
</section>
<!-- Logic-->
<section>
<h2>Logic Operators</h2>
<p>Combine or modify boolean values.</p>
</section>
<section>
<h3>Logic Operator: AND</h3>
<p>Returns true if all values are true.</p>
<p>Otherwise it returns false.</p>
<pre><code contenteditable class ="javascript">
true && true; // true
true && false; // false
false && true; // false
false && false; // false
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
true && true && false; // ???
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
(1 === 1) && ("this" != "that"); // ???
</code></pre>
</section>
<section>
<h3>Logic Operator: OR</h3>
<p>Returns true if any value is true.</p>
<p>Returns false if all values are false.</p>
<pre><code contenteditable class ="javascript">
true || true; // true
true || false; // true
false || true; // true
false || false; // false
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
false || false || true; // ???
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
(3 == 4) || (true); // ???
</code></pre>
</section>
<section>
<h3>Logic Operator: NOT</h3>
<p>Inverts the boolean value.</p>
<pre><code contenteditable class ="javascript">
!false; // true
!true; // false
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
!(1 === 1); // ???
</code></pre>
<pre class="fragment"><code contenteditable class ="javascript">
!(6 > 2); // ???
</code></pre>
</section>
<section>
<h3>Logic Operator: Example</h3>
<div>
<pre><code contenteditable class ="javascript">
var bananas = 5;
var oranges = 2;
if (bananas > 3 && oranges > 3){
console.log('Eat fruit!');
}
if (bananas < 2 || oranges < 2){
console.log('Buy fruit!');
}
if (!(bananas >= 0)){
console.log('How do you have negative bananas?');
}
</code></pre>
</div>
</section>
<section>
<h3>Evaluate to false in <br/>logical expressions</h3>
<p>false isn't the only one</p>
<ul>
<li>false</li>
<li>null</li>
<li>0</li>
<li>empty string ("" or '')</li>
<li>undefined</li>
</ul>
<pre class="fragment"><code contenteditable class ="javascript">
false || null || 0 || "" || '' || undefined; // false
</code></pre>
</section>
<!-- If/else-->
<section>
<h3>If/Else Statement</h3>
<p>You can use else to perform an alternative action if the "if" fails</p>
<pre><code contenteditable class ="javascript">
var bananas = 5;
if (bananas > 3){
console.log('Eat a banana!');
} else {
console.log('Buy a banana!');
}
</code></pre>
</section>
<section>
<h3>If/Else Statement</h3>
<p>You can use else if to have multiple choices</p>
<pre><code contenteditable class ="javascript">
var age = 20;
if (age >= 35) {
console.log('You can vote AND hold any place in government!');
} else if (age >= 25) {
console.log('You can vote AND run for the Senate!');
} else if (age >= 18) {
console.log('You can vote!');
} else {
console.log('You have no voice in government (yet)!');
}
</code></pre>
</section>
<!-- Exercise-->
<section data-state="activity">
<section>
<h3>Let's Develop It!: Welcome</h3>
<p>Output a welcome message</p>
<ul>
<li>Set a variable with the current month (number)</li>
<li>Set a variable with the current day (number)</li>