Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·1793 lines (1608 loc) · 64.4 KB
/
Copy pathindex.html
File metadata and controls
executable file
·1793 lines (1608 loc) · 64.4 KB
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>
<head>
<meta charset="utf-8">
<title>Ladies Learning Code - JavaScript March 18, 2012</title>
<meta name="viewport" content="width=1280">
<!-- CoderDeck core and extension CSS files -->
<link rel="stylesheet" href="src/deck.js/core/deck.core.css" type="text/css">
<link rel="stylesheet" href="src/deck.js/extensions/navigation/deck.navigation.css">
<link rel="stylesheet" href="src/deck.js/extensions/status/deck.status.css">
<link rel="stylesheet" href="src/deck.js/extensions/hash/deck.hash.css">
<link rel="stylesheet" href="src/deck.js/extensions/menu/deck.menu.css">
<link rel="stylesheet" href="src/css/prettify.css">
<link rel="stylesheet" href="src/css/deck.coder.css">
<link rel="stylesheet" href="src/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="src/codemirror/theme/default.css">
<!-- Custom for LLC -->
<link href='http://fonts.googleapis.com/css?family=Istok+Web' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Podkova' rel='stylesheet' type='text/css'>
<link rel="stylesheet" id='style-theme-link' href="src/css/coderdeck.css" type="text/css" >
<style type="text/css"></style>
</head>
<body class="deck-container">
<script type='text/coderdeck' id='coderdeck-default'>
<html>
<head>
<script src='src/jquery.min.js'>SCRIPTEND</head>
<body>CODE</body>
</html>
</script>
<script type='text/coderdeck' id='coderdeck-style-example'>
<html>
<title>test</title>
<style>CODE</style>
<body>
<h1>I'm a H1 heading</h1>
<h2>I'm a H2 heading</h2>
<p>Pargraph of text <p> here</p>
<div class='stuff'>I'm a div <div> with class "stuff"</div>
<div id='my-div'>I'm a <div> with id "my-div"</div>
</body>
</html>
</script>
<div id="presentation">
<!-- SLIDE: Download zip from Github -->
<article class='slide slide-title'>
<div class="workshop_title">
<h1>Introduction to JavaScript</h1>
</div>
<p class="download_link">
<a href='http://github.com/afabbro/LLC-JavaScript-Vancouver'>http://github.com/afabbro/LLC-JavaScript-Vancouver</a>
</p>
<p align="center"><a href="http://github.com/afabbro/LLC-JavaScript-Vancouver"><img src="assets/git-download-zip.jpg" width="566" height="400" alt="Github screenshot of ZIP button"></a></p>
<p style="padding-top: 25px; margin-bottom: 0; font-size: 0.9em; color: #999;">
( Interactive code slides thanks to
<a href="http://cykod.github.com/CoderDeck/" target="_blank" style="color: #999;">CoderDeck</a>
! )
</p>
</article>
<!-- SLIDE: Workshop intro -->
<article class='slide slide-title'>
<div class="workshop_title">
<h1>Introduction to JavaScript</h1>
<p style="font-size: 1em; color: #999;">November 30th, 2013</p>
</div>
<h2>Your instructor today</h2>
<div>
<img src="assets/angelina-tiny.jpg" width="72" height="72" alt="Angelinapants" />
<h4>Angelina Fabbro</h4>
angelinafabbro [at] mozilla.com<br />
<br />
<a href="http://twitter.com/angelinamagnum" target="_blank">@angelinamagnum</a>
</div>
</article>
<!-- SLIDE: Course Outline -->
<article class='slide slide-list'>
<h2>Course Outline</h2>
<h3 style="margin-top: 1em;">The morning (lunch @ ~12:00pm)</h3>
<ul>
<li>What is JavaScript?</li>
<li>JavaScript Theory: variables, operators, and conditionals</li>
</ul>
<h3 style="margin-top: 1em;">After lunch (small break @ ~3:30pm)</h3>
<ul>
<li>JavaScript Theory: functions, objects, arrays, and loops</li>
<li>JavaScript objects and the DOM</li>
</ul>
<h3 style="margin-top: 1em;">Homestretch</h3>
<ul>
<li>Debugging in Chrome and Firefox</li>
<li>Quick intro to jQuery</li>
<li>SPOILER: Javascript on servers and robots?!</li>
<li>Where can you go from here?</li>
<!-- <li>Overview of take home assignment: a photo slider.</li> -->
</ul>
</article>
<!-- SLIDE: Development Environment -->
<article class='slide slide-subhead'>
<h1>Development Environment</h1>
<p>3 tools you need to get started</p>
</article>
<!-- SLIDE: Web Browser -->
<article class='slide slide-list'>
<h2>1. Web Browser</h2>
<p>
Choose a modern web browser that has good, built-in development tools to help make building web pages easier. Choose Firefox or Chrome! (Today we'll all use Chrome for simplicity)
</p>
<div class="centered contains_sidebyside_icons">
<a href="https://www.google.com/chrome" target="_blank"><img src="assets/new-chrome-logo.png" width="125" height="125" alt="Chrome" /></a>
<br/>
<a href="https://www.google.com/chrome" target="_blank">Google Chrome</a>
</div>
<br clear="all" />
</article>
<!-- SLIDE: Code Editor -->
<article class='slide slide-list'>
<h2>2. Code Editor</h2>
<p>
There are many, many free and paid options* but let's keep it simple for our mentors today and use just one of these two to edit our code.
</p>
<div class="centered contains_sidebyside_icons">
<div class="sidebyside_download_icon">
<a href="http://notepad-plus-plus.org/" target="_blank"><img src="assets/Notepad.png" width="169" height="125" alt="Notepad++" /></a>
<br />
<a href="http://notepad-plus-plus.org/" target="_blank">Notepad++</a>
(Windows)
</div>
<div class="sidebyside_download_icon">
<a href="http://www.barebones.com/products/textwrangler/" target="_blank"><img src="assets/textWranglerIcon.png" width="125" height="125" alt="Text Wrangler" /></a>
<br />
<a href="http://www.barebones.com/products/textwrangler/" target="_blank">TextWrangler</a>
(Mac)
</div>
</div>
<br clear="all" />
<br />
<br />
<br />
<p class="sidenote centered">
*I like to use <a href="http://www.sublimetext.com/" target="_blank">Sublime Text</a>. There are a lot of editors out there, some are used only with terminal output and no GUI!</a>.
<br />
Ask a group of developers what they use and arguments will ensue -- it's a very personal choice! ;)
</p>
</article>
<!-- SLIDE: FTP -->
<article class='slide slide-list'>
<h2>3. File Transfer Program (FTP)</h2>
<p>
FTP software will let you copy the files you work on today to another computer that is specially set up to send people your webpage when it is requested. <br />If you're already set up, ask your mentor about what a web server is or help someone else get started.
</p>
<div class="centered contains_sidebyside_icons">
<a href="http://cyberduck.ch/" target="_blank"><img src="assets/Cyberduck_icon.png" width="125" height="125" alt="CyberDuck" /></a>
<br />
<a href="http://cyberduck.ch/" target="_blank">CyberDuck</a>
</div>
<br clear="all" />
<br />
<br />
<br />
<p class="sidenote centered">
Again, there are many, many free and paid options.
<br />
<a href="http://filezilla-project.org/" target="_blank">FileZilla</a>
is good when you're more advanced.
</p>
</article>
<!-- new slide -->
<article class='slide slide-subhead'>
<h1>Technology Overview</h1>
<p>Programming and JavaScript</p>
</article>
<!-- SLIDE: What is JavaScript? -->
<article class='slide slide-list'>
<h2>What is JavaScript?</h2>
<p class="centered" style="font-size: 2.5em; margin-top: 2em;">
It's a
<span class="keyword">programming language</span>
<br><br>
that was designed to <strong>run in your web browser</strong> to
<br><br>
<strong>manipulate content on web pages</strong>.
</p>
</article>
<!-- SLIDE: What is JavaScript? -->
<article class='slide slide-list'>
<h2>What is JavaScript?</h2>
<p class="centered" style="font-size: 2.5em; margin-top: 2em;">
It's a
<span class="keyword highlight">programming language</span>
<br><br>
that was designed to <strong>run in your web browser</strong> to
<br><br>
<strong>manipulate content on web pages</strong>.
</p>
</article>
<!-- SLIDE: What is Programming? -->
<article class='slide slide-list'>
<h2>What is Programming?</h2>
<p>
A
<span class="keyword">program</span>
is a <strong>set of instructions</strong>
meant for a computer to execute.
</p>
<p>Computers are fast but blind.</p>
<p class="centered"><img src="assets/blindfold.gif" width="377" height="270" alt="As the first step to our new system integration, please take a blind fold."></p>
</article>
<!-- SLIDE: Instructions -->
<article class='slide slide-list'>
<h2>Programming is giving instructions to your computer</h2>
<p>
Think about a tourist that stops you to ask for directions:</p>
<p>
<strong>The clearer the instructions, the more likely they will get to their destination. </strong></p>
<p class="centered"><img src="assets/Map.png" width="252" height="222" alt="Give clear directions" /></p>
</article>
<!-- SLIDE: Instructions -->
<article class='slide slide-list'>
<h2>Break your goal down into steps</h2>
<p>Suppose I want a computer to say hello using my name. </p>
<p><strong>Break down the steps</strong> as much as possible: </p>
<ol>
<li>Allow me to type in my name.</li>
<li>Remember my name.</li>
<li>Say "Hello" and repeat back my name.</li>
</ol>
</p>
</article>
<!-- SLIDE: What is a Programming Language? -->
<article class='slide slide-list'>
<h2>Speak the computer's language</h2>
<p>Programming is like having a <strong>conversation</strong> with your computer. You write to it using a <strong>programming language</strong> and give it instructions this way.</p>
<p>
Computers only understand instructions when you speak to them in a language they can understand. Much like Japanese, English or any other natural language, programming is about sticking to grammar rules called <span class="keyword">syntax</span>.
</p>
<p><img src="assets/beepbeep.jpg" height="300" alt="Beep beep" align="left" style="margin-right: 40px;" /> Computers have come a long way since their binary days (<code>0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 1</code>) so meet them half-way.</p>
<br clear="all" />
</article>
<!-- SLIDE: What is a Programming Language? -->
<article class='slide slide-list'>
<h2>Example Programming Syntaxes</h2>
<p>Different programming languages have different syntax.</p>
<p>Here are two ways a computer could say hi to me:</p>
<p>
<strong>Java</strong></p>
<pre class="prettyprint">Scanner userInput = new Scanner(System.in);
String name;
System.out.print("What's your name? ");
name = userInput.next();
System.out.println("Hello, " + name);</pre>
<p>
<strong>JavaScript</strong> ( <a href="exercises/hello-javascript.html">Try it out now!</a>
)</p>
<pre class="prettyprint">var name;
name = window.prompt("What's your name?",'');
document.write("Hello, " + name);</pre>
</article>
<!-- SLIDE: JavaScript versus Java -->
<article class='slide slide-list'>
<h2>JavaScript versus Java</h2>
<p>
They might vaguely look the same (as a lot of programming languages do) but <strong>they are not related at all</strong>. </p>
<p class="centered">
<img src="assets/llcodedotcom_hamster.gif" width="544" height="220" alt="Java is to JavaScript as ham is to hamster." />
</p>
<p class="centered sidenote">(Java was really popular at the time so Netscape just hijacked the name.) </p>
</article>
<!-- SLIDE: What is JavaScript? -->
<article class='slide slide-list'>
<h2>What is JavaScript?</h2>
<p class="centered" style="font-size: 2.5em; margin-top: 2em;">
It's a
<span class="keyword">programming language</span>
<br><br>
that was designed to <strong class="highlight">run in your web browser</strong> to
<br><br>
<strong>manipulate content on web pages</strong>.
</p>
</article>
<!-- SLIDE: JavaScript in the Browser -->
<article class='slide slide-list'>
<h2>JavaScript in the Browser</h2>
<p>
C++, Java, and .NET are also programming languages but they can be run directly by the <strong>operating system</strong>
(e.g. Windows, Mac, Linux).
</p>
<p>
JavaScript is typically meant to be run in a
<strong>web browser</strong>
(e.g. Safari, Firefox, Chrome, Internet Explorer).*
</p>
<p class="centered">
<img src="assets/scripting.gif" width="586" height="224" alt="Different programmig languages and the environments they run in" />
</p>
<small>* Angelina will tell you about how Javascript outgrew it's origins towards the end of today's course!</small>
</article>
<!-- SLIDE: Web Programming Languages: Server-side vs Client-side-->
<article class='slide slide-list'>
<h2>Web Programming Languages: Server-side vs Client-side</h2>
<p><img src="assets/clientversusserver.gif" width="400" height="400" alt="" align="right" style="margin-left: 30px;" /></p>
<p>
Java, .NET, PHP or Ruby can be considered <strong>server-side or "back-end"</strong> web technology because the code is typically compiled and executed by the <em>operating system</em> of a computer serving up web pages. </p>
<p>
JavaScript is often referred to as a <strong>client-side or "front-end"</strong> web technology because it is interpreted by the <em>web browser</em>. It can be used for server-side programs too, but today we'll be focusing on the browser.</p>
</article>
<!-- SLIDE: -->
<article class='slide slide-list'>
<h3>Simple Client-Side Code Check</h3>
<p><br>
<img src="assets/llcodedotcom_viewsource.gif" width="468" height="362" alt="Right-click to View Source" align="left" style="margin-right: 50px;" />
</p>
<p>
<br>
At any time, someone can <strong>right-click and "view source" OR CTRL/CMD-U</strong> on a web page to see all the JavaScript that went into it.</p>
<p class="sidenote">(I suggest that you do this yourself every time you see something you like!)</p>
</p>
<br clear="all" />
<p>
Whereas for server-side code, it's sometimes a mystery what technology is running on a server.
</p>
</article>
<!-- SLIDE: What is JavaScript? -->
<article class='slide slide-list'>
<h2>What is JavaScript?</h2>
<p class="centered" style="font-size: 2.5em; margin-top: 2em;">
It's a
<span class="keyword">programming language</span>
<br><br>
that was designed to <strong>run in your web browser</strong> to
<br><br>
<strong class="highlight">manipulate content on web pages</strong>.
</p>
</article>
<!-- SLIDE: The Web Triad -->
<article class='slide slide-list'>
<h2>The Web Triad</h2>
<p>
JavaScript was meant to manipulate webpages written in HTML and works in tandem with CSS.
</p>
<table width="100%">
<tr>
<td width="33%" class="centered"><strong>HTML</strong> (Hypertext Markup Language) <br>
is the markup language.</td>
<td width="33%" class="centered"><strong>CSS</strong> (Cascading Style Sheets) <br>
is the style sheet language.</td>
<td width="33%" class="centered"><strong>JavaScript</strong><br>
is the programming language.</td>
</tr>
<tr>
<td class="centered"><img src="assets/TRIAD-html.gif" width="267" height="241" alt="content layer"></td>
<td class="centered"><img src="assets/TRIAD-css.gif" width="261" height="241" alt="Presentation Layer" /></td>
<td class="centered"><img src="assets/TRIAD-js.gif" width="274" height="241" alt="Behaviour Layer" /></td>
</tr>
<tr>
<td class="centered">It should define the <strong>content</strong>.</td>
<td class="centered">It should define the <strong>presentation</strong></td>
<td class="centered">It should define <strong>behaviour</strong>.</td>
</tr>
</table>
</article>
<!-- SLIDE: -->
<article class='slide slide-list'>
<h2>JavaScript in Different Browsers</h2>
<p class="reminders">
Usually JavaScript will run the same way in various browsers.
</p>
<p>
But, browsers are software programs written by many different people/companies (people programming things just like you!), so sometimes they say "hi" with different accents.</p>
<p> Imagine a British accent versus a Texas accent.</p>
<p>This is especially noticeable with newer "HTML5" features.</p>
<p class="centered"><img src="assets/browser-war-illustration.jpg" height="300" /></p>
</article>
<!-- SLIDE: -->
<article class='slide slide-list'>
<h2>A JavaScript Experiment</h2>
<p>
JavaScript is essential for "AJAX", "Web 2.0", and "HTML5" websites. All these terms refer to various methods of making interactive web pages using Javascript.
</p>
<p>
Try this experiment: Turn off JavaScript in your web browser. Go to the JavaScript settings for Chrome (
<a href="chrome://settings/content">chrome://settings/content</a>
) and select "Do not allow any site to run JavaScript"
</p>
<p>Then visit your daily sites.</p>
<p>
e.g.
<a href="http://google.com">Google</a>
,
<a href="http://facebook.com">Facebook</a>
,
<a href="http://twitter.com">Twitter</a>
</p>
<p> <em>(Remember to turn JavaScript back on to see this presentation!)</em>
</p>
</article>
<!-- SLIDE: -->
<article class='slide slide-list'>
<h2>A JavaScript Experiment: Results</h2>
<p>Note the sometimes subtle and sometimes major differences:</p>
<ul>
<li>
No search auto-completion and instant page refreshes on google.com
</li>
<li>
No inline video content or lightboxed photo viewers on facebook.com -- not to mention broken "Like" buttons and inability to comment on posts!
</li>
<li>
On twitter.com - older tweets don't load at the bottom of the page. Warning message on top of page. Navigation doesn't work. Popups don't work.
</li>
<li>
And <strong>you can't see it but most analytics tracking won't work</strong> either. </li>
</ul>
<p class="reminders" style="font-size: 2.2em;">
<strong>The modern web just sort of gives up without JavaScript!</strong>
</p>
</article>
<!-- SLIDE: -->
<article class='slide slide-list'>
<h3>JavaScript helps us make nice websites</h3>
<p>
Especially "one-page apps" where the experience is very seamless.
</p>
<p class="centered">
<a href="http://thenewdesignguidelines.derekevanharms.com/" target="_blank"><img src="assets/thenewdesignguidelines.gif" width="800" height="479" alt="The new web design guidelines" /></a> <br>
<span class="sidenote">Like
<a href="http://thenewdesignguidelines.derekevanharms.com/" target="_blank">this one</a></span></p>
</article>
<!-- SLIDE: PART 1 INTRO -->
<article class='slide slide-subhead'>
<h1>JavaScript Theory<br />Hands-on</h1>
<p>Part 1</p>
</article>
<!-- SLIDE: EXERCISE OVERVIEW -->
<article class='slide slide-list'>
<p>As the owner of the thriving store, <span style="color:#B1009A;font-weight:bold;">Planet Robots</span>, you have to make sure you have a top notch website.</p>
<div class="centered">
<img src="assets/planet-robots.jpg" alt="planet-robots" />
</div>
</article>
<!-- SLIDE: EXERCISE OVERVIEW -->
<article class='slide slide-list'>
<h2>JavaScript Exercise Overview</h2>
<br />
<p>You'll want to do things like offer online shopping, print shipping labels and tempt loyal customers with members only sales!</p>
<p>You'll also want to make sure that everything works properly as well.</p>
<p>That means customers shouldn't be able to submit empty forms and product totals must be calculated properly in their shopping carts.</p>
<p>In order to create a website that can handle these requirements, we will need to learn how to use <span class="keyword">variables</span>, <span class="keyword">functions</span>, <span class="keyword">objects</span>, <span class="keyword">arrays</span> and <span class="keyword">loops</span>.</p>
</article>
<!-- SLIDE: VARIABLES -->
<article class='slide slide-list'>
<h2>Variables</h2>
<br />
<p><span class="keyword">Variables</span> are used to store values.</p>
<p><strong>Declaring</strong> a variable tells the computer that it exists and to<br />
remember it.</p>
<p>Variables are like boxes; it can be used to store different things.</p>
<img src="assets/gift-boxes.jpg" alt="gift-boxes" width="400" height="300" />
</article>
<!-- SLIDE: VARIABLES (cont'd) -->
<article class='slide slide-list'>
<h2>Variables (cont'd)</h2>
<br />
<p><img src="assets/computer-memory.jpg" alt="computer-memory" width="200" height="207" style="float:right;padding:0 40px 0 10px;" />Variables are also like the computer's short-term memory. It doesn't remember anything unless you tell it to.
In this example, the computer can't remember anyone's name!</p>
<br /><br />
<textarea class='coder-editor coder-editor-full'>
<script>
prompt("What's your name?");
document.write("Hello....?");
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: VARIABLES (cont'd) shipping example -->
<article class='slide slide-list'>
<h2>Variables (cont'd)</h2>
<br />
<p>
In a web checkout form that asks for your name and address, variables can be used to store this information.
Then they can be used to create things like shipping labels.</p>
<br />
<p>
<img src="assets/var-shipping-example.jpg" width="594" height="193" />
</p>
</article>
<!-- SLIDE: AN ASIDE -->
<article class='slide slide-list'>
<h2>An Aside...</h2>
<br />
<p>Before we continue, here's a few helpful JavaScript built-ins that will help with testing and writing code.</p>
<textarea class='coder-editor coder-editor-full'>
<script>
alert("This is an alert box.");
prompt("This is a prompt box. Enter some info.");
document.write("document.write outputs text into the page.");
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: VARIABLES HOW-TO -->
<article class='slide slide-list'>
<h2>Variables How-to</h2>
<p>Declare variables with the keyword <strong>var</strong>.</p>
<pre class='prettyprint'>var email;</pre>
<p>Assign a value to the variable using the equals (=) sign.
<br />End the <strong>statement</strong> with a semicolon (;).
</p>
<pre class='prettyprint'>var email = "hello@isanybodyoutthere.com";</pre>
<p>Now the computer will remember my email address!</p>
<br />
<div class="reminders">
<p><strong>Statements</strong> are commands that tell the computer what to do.
<br />
Ending the statement with a semicolon is like ending a sentence
<br />
with a period. It tells the computer that the statement is done.
</p>
</div>
</article>
<!-- SLIDE: VARIABLES - assignment operator -->
<article class='slide slide-list'>
<h2>Assigning Variables</h2>
<br />
<p><span class="assignment">IMPORTANT!</span></p>
<p>Using the equals (=) symbol in Javascript is <span class="highlight">NOT</span> the same as in math.</p>
<p><code>var total = 1 + 1</code>
is not the same as
<code>1 + 1 = 2</code>
</p>
<p>You will see later that we can change the <strong>value</strong> of a variable.</p>
<p>Variables are assigned a value with whatever you place to the right of '='.</p>
</article>
<!-- SLIDE: VARIOUS VARIABLES -->
<article class='slide slide-list'>
<h2>Various Variables</h2>
<p>Variables can hold different kinds of values.</p>
<p>1. Numeric variable (integers & decimals)</p>
<pre class='prettyprint'>
var someIntegerNumber = 10;
var someDecimalNumber = 10.5;</pre>
<p>2. String variable (letters, words & sentences)</p>
<pre class='prettyprint'>
var singleWordString = "hello";
var sentenceString = "Hello, good day to you!";
var numberString = "10";
</pre>
<br />
<p>3. Boolean variable (true/false)</p>
<pre class='prettyprint'>
var isSaturday = false;
var isSunday = true;
</pre>
<div class="reminders single-line">
<p>String values are always written inside single or double quotes ('string' or "string").</p>
</div>
<br />
</article>
<!-- SLIDE: VARIABLES - UNDERSCORES AND $ SIGNS -->
<article class='slide slide-list'>
<h2>Variables: Tips & Best Practices</h2>
<p>
Variables cannot start with a number or any special characters except for underscores (_) and dollar signs ($).
</p>
<div class="reminders">
<p>Although it's valid to use underscore or a dollar sign, it is not used often
<br />and usually only in special circumstances.
</p>
</div>
<br />
<textarea class='coder-editor'>
<script>
var 3hundred = 300;
console.log(3hundred);
//var $1000 = 1000;
//document.write($1000);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: VARIABLE NAMES - NO SPACES -->
<article class='slide slide-list'>
<h2>Variables: Tips & Best Practices</h2>
<p>Variables can't contain spaces. Use a convention called <span class="keyword">camel case</span>.
<br />Every new word is capitalized and the result looks <strong>likeCamelHumps</strong>.
</p>
<p>JavaScript is case sensitive so variable names are also case sensitive.</p>
<p>Another convention is to use underscores <strong>to_separate_words</strong>. This is common in other programming languages (like PHP).</p>
<textarea class='coder-editor coder-editor-full'>
<script>
var greetMe = prompt("Hello, what's your name?");
var greetme = prompt("Bonjour, quel est ton nom?");
var greet_me = prompt("Hola, ¿cómo te llamas?");
document.write(greetMe);
document.write("<br />");
document.write(greetme);
document.write("<br />");
document.write(greet_me);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: VARIABLES - DESCRIPTIVE NAMES -->
<article class='slide slide-list'>
<br />
<h2>Variables: Tips & Best Practices</h2>
<p>
When naming a variable, it's best to give it a descriptive name.
</p>
<p>
It makes it easier to see at a glance, what kind of value that variable is going to hold.
</p>
<p>
This is especially useful when sharing code with others who may not use the same kinds of abbreviations.
</p>
<p>
<strong><span class="var">var</span> firstName;</strong> ← Clear that first name will go here.
<br />
<strong><span class="var">var</span> fn;</strong> ← Not as obvious as firstName.
<br />
<strong><span class="var">var</span> x;</strong> ← Not clear at all.
</p>
</article>
<!-- SLIDE: WHITESPACE -->
<article class='slide slide-list'>
<h2>Whitespace in JavaScript</h2>
<p>
Whitespace refers to blank characters and includes space characters, tabs and line breaks.
</p>
<p>JavaScript ignores whitespace except when used in a string.</p>
<pre class="prettyprint">
var name="Angelina";
//same as
var name = "Angelina";
</pre>
<textarea class='coder-editor coder-editor-full'>
<script>
alert("Whitespace in a string.");
document.write("Whitespace in a string.");
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: COMMENTS -->
<article class='slide slide-list'>
<h2>Comments</h2>
<p>
Sometimes you want to write notes to yourself (and others!) to organize blocks of code or leave explanations, but you want the browser to ignore it. Use comments!
</p>
<pre class='prettyprint'>
// This is how you leave a single line comment.
// You can write many single line comments.
// Just make sure to add the double backslash
// for every new line.</span>
</pre>
<p>Here's another way to comment larger blocks of text.</p>
<pre class='prettyprint'>
/* This is how you leave
multi-line comments for when you
want to write a longer message */
</pre>
<p>Multi-line comments are great for "hiding" large blocks of code so you can try something new without erasing your old code. Don't forget to remove the old code later if you decide that you don't need it though!</p>
</article>
<!-- SLIDE: MINI-EXERCISE #1 -->
<article class='slide slide-list'>
<h2>Mini-exercise #1 (5-10 minutes)</h2>
<p>
Here's a test shipping form. Right now, after you press Run, the shipping label is blank. How do we fix this?
</p>
<div class="hint">
<p>(1) Use variables to store your name and address!<br />
(2) To verify that your variables are working, uncomment out the document.write() lines and replace ********** with the actual name of your variables.
</p>
</div>
<textarea class='coder-editor coder-editor-full' data-save='exercise1'>
<script>
//The web browser will ask you for your shipping details.
//Declare a "name" and an "address" variable to remember the values.
prompt("What's your name?");
prompt("Your mailing address?");
//Confirm that your package will be shipped to the right place!
document.write("<b>Confirm Shipping Label:</b><br />");
/*
document.write(**********); //output the name
document.write("<br />"); //just a line break
document.write(**********); //output the address
*/
</script>
</textarea>
<script type='coder-solution'>
SCRIPT
/** SOLUTION **/
//The web browser will ask you for your shipping details.
//Declare a "name" and an "address" variable to remember the values.
var name = prompt("What's your name?");
var address = prompt("Your mailing address?");
//Confirm that your package will be shipped to the right place!
/*
document.write("<b>Confirm Shipping Label:</b><br />");
document.write(name); //output the name
document.write("<br />"); //just a line break
document.write(address); //output the address
*/
SCRIPTEND
</script>
<span class="marker">*</span>
</article>
<!-- SLIDE: OPERATORS -->
<article class='slide slide-list'>
<h2>JavaScript Arithmetic Operators</h2>
<p>We can use JavaScript to do math using arithmetic <span class="keyword">operators</span>.</p>
<p>The arithmetic operators in JavaScript are (+) for addition, (-) for subtraction, (*) for multiplication and (/) for division.</p>
<textarea class='coder-editor'>
<script>
document.write(20 + 20);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: OPERATORS & VARIABLES -->
<article class='slide slide-list'>
<h2>Arithmetic Operators and Variables</h2>
<p>Getting JavaScript to do math can be very useful.<br />
For example, we can use it to calculate totals in a shopping cart form.</p>
<p>Instead of using just numbers, JavaScript can do math using variables with numerical values.</p>
<textarea class='coder-editor coder-editor-full'>
<script>
var tshirtPrice = 25;
var androidPrice = 10;
document.write(tshirtPrice + androidPrice);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: OPERATORS & ADDING STRINGS VS NUMBERS -->
<article class='slide slide-list'>
<h2>Arithmetic Operators,<br />
Numbers & Strings</h2>
<br />
<p>Remember there were different variable types? Arithmetic operators can only be performed on numerical values.</p>
<p>But numbers can be declared as strings too, so be careful!</p>
<p>If you put double quotes (" ") or single quotes (' ') around the value, the computer will thinks it's a string.</p>
<textarea class='coder-editor coder-editor-full'>
<script>
var firstNumber = "20";
var secondNumber = 10;
document.write(firstNumber + secondNumber);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: ADD SHOPPING CART ITEMS -->
<article class='slide slide-list'>
<h2>Shopping Cart: Totals and Discounts</h2>
<p style="margin-bottom:0;">Let's try applying some arithmetic operations to our shopping cart.</p>
<div class="reminders single-line">
<p>addition (+), subtraction (-), multiplication (*), division (/)</p>
</div>
<br />
<textarea class='coder-editor coder-editor-full'>
<script>
var tshirtPrice = 25;
var androidPrice = 10;
var discountPercentage = 15;
// What is the cost of one t-shirt and one android?
var total;
//total = **********
document.write(total);
document.write("<br />");
// Guess what? Ladies Learning Code gets 15% off!
// Figure out how much the discount will be.
var discountAmount;
//discountAmount = **********
//document.write(discountAmount);
document.write("<br />");
// Apply the discount to get the final price.
var finalTotal
//finalTotal = **********
//document.write(finalTotal);
</script>
</textarea>
<span class="marker">*</span>
</article>
<!-- SLIDE: INCREMENT AND DECREMENT -->
<article class='slide slide-list'>
<h2>Re-assigning Variables</h2>
<p>Even after a variable has been declared with a value, we can still<br />
<strong>re-assign</strong> the value. For example, we may want to increase or decrease values by 1. This will come in handy when we discuss <strong class="keyword">Loops</strong> later on.
</p>
<textarea class='coder-editor coder-editor-full'>
<script>
//declaring variable
var numberOfCookies = 0;
//re-assigning the value by adding 1
numberOfCookies = numberOfCookies + 1;
alert("I will only have " + numberOfCookies + ".");
//declaring another variable
var remainingCookies = 4;
//re-assigning the value by subtracting 1
remainingCookies = remainingCookies - 1;
alert("I just ate a cookie. Now I have " + remainingCookies + " left.");
</script>
</textarea>
</article>
<!-- SLIDE: "LIKE" BUTTON -->
<article class='slide slide-list'>
<h2>Who loves LadiesLearningCode?</h2>
<p>Don't worry about the function or unfamiliar parts right now. You will be familiar with them soon enough.</p>
<p>Run it and see what happens!</p>
<textarea class='coder-editor coder-editor-full'>
<link rel="stylesheet" type="text/css" href="exercises/slides.css">
<script>
var loves = 0;
function moreLove(){
//re-assigning the value of the love variable
loves = loves + 1;
document.getElementById('update').innerHTML = loves;
}
</script>
<div id="loveLLC">
<button onclick="moreLove();">
<img src="exercises/assets/llc-logo.png" /> Love!
</button>
<p id="update">0</p>
</div>
</textarea>
</article>
<!-- SLIDE: MINI-EXERCISE #2 - ADD/REMOVE ITEMS - ONE PRODUCT -->
<article class='slide slide-list'>
<h2>Mini-exercise #2</h2>
<br />
<p>Here's a one-product shopping page where you can update the<br />
quantity by adding or removing it from the shopping cart.</p>
<p>Here's what it will look like.</p>
<img src="exercises/assets/android-quantity.png" alt="android-quantity" width="225" height="282" />
<p>Go to the next slide to get the exercise code.</p>
</article>
<!-- SLIDE: MINI-EXERCISE #2 : Code page -->
<article class='slide slide-list'>
<h2>Mini-exercise #2: Go! (5-10 minutes)</h2>
<div class="hint single-line">
<p>How do we increase or decrease the value of the variable?</p>
</div>
<textarea class='coder-editor coder-editor-full' data-save='exercise2'>
<script>
/* 1. set var 'quantity' to start at 0. This will be
used to hold the value for the quantity of robots */
var quantity =
function addItem(){
// CODE HERE EXECUTES WHEN YOU PRESS THE 'ADD' BUTTON
//2. set the variable 'quantity' to increase by 1 HERE
refreshTotal();
}
function removeItem(){
// CODE HERE EXECUTES WHEN YOU PRESS THE 'REMOVE' BUTTON
//3. set the variable 'quantity' to decrease HERE
refreshTotal();
}
function refreshTotal() {
var totalCost = quantity * 20; //quantity * fixed price
document.getElementById('updateQuantity').value = quantity; //updates
}
</script>
<link rel="stylesheet" href="exercises/slides.css" type="text/css" />
<div class="item">
<img src="exercises/assets/plush-android.jpg" width="195" height="195" />
<br />
<button onclick="addItem();">Add</button>
<button onclick="removeItem();">Remove</button>
<br />
Quantity
<input type="text" id="updateQuantity" value="0" readonly />
<br />
</div>
</textarea>
<script type='coder-solution'>
<!-- SOLUTION -->
SCRIPT
/* 1. set var 'quantity' below to start at 0. This is the variable will be used to hold
the value for the quantity of robots */
var quantity = 0;
function addItem(){
//2. set the variable 'quantity' to increase by 1 HERE
quantity = quantity + 1;
refreshTotal();
}
function removeItem(){
//3. set the variable 'quantity' to decrease by 1 HERE
quantity = quantity - 1;
refreshTotal();
}
function refreshTotal() {
var totalCost = quantity * 20; //quantity * fixed price
document.getElementById('updateQuantity').value = quantity; //updates
}
SCRIPTEND
<link rel="stylesheet" href="exercises/slides.css" type="text/css" />
<div class="item">
<img src="exercises/assets/plush-android.jpg" width="195" height="195" />
<br />
<button onclick="addItem();">Add</button>
<button onclick="removeItem();">Remove</button>
<br />
Quantity