Intro to Javascript
Basic Training
Session 2
2
As a community, we will...
Be present, physically and mentally
Actively build an inclusive community and space
Practice curiosity and adopt a learning mindset
Ask for help when we need it
Keep our cameras on
Your TA today
3
Harvey Zhao
(He/Him)
Course Expectations
5 minutes
Course Overview
This lecture, we will cover topics including…
5
Programming Language
Python 3 | Java 8
Session Goals
At the end of this class you will be able to...
6
Policies: Attendance
7
Breakout Rooms
8
IceBreaker!
10 min
15 mins
10
Breakout Rooms
Questions? Post on Slack and tag:
Javascript Basics
120 minutes
What is Javascript?
12
Hello World
13
Hello World
14
Node.js�
15
Variables & Primitive Types!
Variables�
17
Variable Scope
18
Variable Scope
19
Variable Scope: var vs const vs let
20
Question Break
5 min
Primitive Types�
22
Primitive types are immutable�
23
Variable Exercise
5 minutes
10 minutes
25
Breakout Rooms
Questions? Post on Slack and tag:
The Age Calculator
Want to find out how old you'll be? Calculate it!
26
Solution
const birthYear = 1984;
const futureYear = 2012;
const age = futureYear - birthYear;
console.log('I will be either ' + age + ' or ' + (age - 1));
27
Question Break
2 min
Type Coercion & Operators
For fun - Type Coercion: equal or not equal?
30
Type Coercion: equal or not equal?
31
Comparison Operators
32
Logical Operators
33
Short-circuit Eval
34
Question Break
5 min
Functions
Important! JavaScript Functions
37
JavaScript Functions
38
Function: Arguments
39
Functions: Return Values
40
JavaScript Functions
41
Beware: Circular Dependencies�
42
Question Break
2 min
Function Exercises
25 min
The Lifetime Supply Calculator
Ever wonder how much a "lifetime supply" of your favorite snack is? Wonder no more!
45
Solution
var maxAge = 100;
var totalNeeded = (numPerDay * 365) * (maxAge - age);
var message = 'You will need ' + totalNeeded + ' cups of tea to last you until the ripe old age of ' + maxAge; console.log(message);
}
calculateSupply(28, 36);
calculateSupply(28, 2.5);
calculateSupply(28, 400);
46
The Calculator
1. Take the half of the number and store the result.
2. square the result of #1 and store that result.
3. Calculate the area of a circle with the result of #2 as the radius.
4. Calculate what percentage that area is of the squared result (#3).
47
Solution
48
Solution
49
JavaScript Functions Review
50
Biggggg Break
10 min
For fun - Javascript Functions: first-class citizens
52
Javascript Functions: first-class citizens
53
For fun - Anonymous Functions
54
DS: Array
Array Data Type
An array is a type of data-type that holds an ordered list of values, of any type:
56
Array Access
57
Changing Arrays
58
Question Break
2 min
Conditionals & Loop
Conditionals
61
The if/else if/else statement�
62
Loops: while loop
63
Loops: For Loop
64
Loops: For Loops – other ways to do it
65
Using for loops with arrays and strings
66
The break statement�
67
Question Break
2 min
Arrays + conditionals Exercises
30 min
1. The Grade Assigner
70
2. The Grade Assigner +
71
3. Your top choices
72
The Grade Assigner: Solution
73
The Grade Assigner + Solution
74
Your top choices: solution
75
Question Break
2 min
Big Break!
10 min
For fun: Anonymous Functions
78
For fun: Objects vs Primitives: Array
79
For fun: Objects vs Primitives: Array
80
For fun: Spread Operator: real copy object
81
For fun: Spread Operator: real copy object
82
Question Break
2 min
Objects
Objects: mother of every data type
85
Object: Mother of all data types
86
Object
87
Objects: Access
88
Changing Objects
89
Arrays of Objects�
90
Objects as Arguments
91
Object Methods
92
Question Break
2 min
The Reading List
Keep track of which books you read and which books you want to read!
94
The Reading List: Solution
95
JS in action
Using JS to manipulate DOM
97
Using JS to manipulate DOM
98
Using JS to manipulate DOM
99
addEventListener(string eventName, function callBack)
100
addEventListener(string eventName, function callBack)
101
Callback function
102
Question Break
2 min
Event Listener Exercises
25 min
Wrap Up
10 minutes
Before you leave...
106