4. Javascript
4. Javascript
Lesson objectives
Students self learn through UDACITY course: https://classroom.udacity.com/courses/ud803
Students understand how to find help on the internet
Understand variables
Understand basic javascript syntax (if, for loops)
Understand functions
Understand how to use the browser console and debugger
Lesson time to deliever:
2 days (6 sessions, 9hrs)
Teacher instruction
This is a relatively easy 2 days for the teacher: The students will mostly self learn through the udacity course
Students go through udacity course (https://classroom.udacity.com/courses/ud803)
In every 1.5 hr session, give students roughly 1h15m to go through course. Then spend 15 mins checkpointing them to ensure they stay on track. Mini quiz (e.g. multiple choice questions), go over bits that class is struggling with.
At end of wednesday 1 or start of Thursday give them the Fizz buzz challenge (see below). Should take 30 mins-1hr to complete. This tests their knowledge of selection (if statements) and iteration (for loops).
Order to cover lessons:
Session
Lesson
Wednesday 1
Wednesday 2
Wednesday 3
Thursday 1
Thursday 2
Thursday 3
May need to teach this one using material below rather than using udacity course due to time constraints
You need to cover an estimated 2hr lesson in effectively 1h15m in each session. Encourage students to go through lessons quickly. Give students homework if unable to do in time
There is some additional material below:
Go through basics (see below: Arrays, objects, selection, for loops) and explain difference between let and var (prefer let), and == vs === (prefer ===) Then cover functions in javascript
Cover getting help: - Stackoverflow - I use this for JS reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
Datatypes: Cover this sparingly and more through examples. Don't cover bigInt, or the max and min of number (Never hit those limits myself)
History of Javascript
JS has a very interesting history so try to get that across:
It was invented in weeks. Most languages are invented in months or years
It was named Javascript to steal from the popularity of Java which was the hottest language at that time. Backfired now as JS is most popular language in the world and Java is gaining the benifits of that...
The browser wars. Can make it into a cool game
JS didnt change in 10 years. Can talk about the drama between Mircosoft (supported by Yahoo on the commitee) that had its own browser scripting language (JScript) vs the other 4 members of the committee. But best thing for JS as people invented tools to fill in its gaps and it was really stable when JScript and Flash it's main competitors were constantly changing.
Ajax - Asynchronous programming. Got invented for JS by open source projects. Now used in most other languages
End with Modern js frameworks which we will cover in the future (React.js, vue.js, angular)
Course materials
Slide deck by emmanuel.
Image on history of JS
Youtube video
https://javascript.info/ - Chpt 2: JS fundamentals
https://classroom.udacity.com/courses/ud803 - Student excerises
Code pen
https://codepen.io/ My favourite html/js playground. Tons of work people have done
Debugging
Enuse you: Cover opening the browser debugger by pressing F12. Chrome is recommended browser as it is the easiest for debugging.
Then execute the js code in the browser console so students get used to it. But also switch to html file + js file so don't forget that.
JS Basics:
Open browser. Press F12. Now have developer console. Can run js code
== Vs ===
As a general rule always use === and never ==
let vs var vs const
If don't use a keyword, variable is declared on Global scope. Aka global variable. Bad!
"var" original way of declaring a variable. Behaves a bit funkily at times
"let" is new way - Prefer over var. Difference is around how they behave within scopes. E.g. a for loop. If you have programmed before "let" behaves the way you are used to. "var" is different
"const" - Constant. Value is not allowed to change (aka be set again) (Prefer this over let when can use)
No strong types in javascript
Functions
Arrow functions (save for full course)
The arrow function expression (=>). Very similar to C#
Self invoking functions (save for full course)
The function invokes as soon as the script is loaded. See it alot in jquery
Function hoisting (save for full course)
Scripted but functions get read first so can call them from anywhere in script
Teacher Recommendations
What worked well in the past
What hasn't worked well in the past
Class Ex: Fizz buzz
HW Fizz Buzz -Fun drinking game and teaching tool for division for kids. Count from 1 to 100. For each number output "This is X out of 100" Any number divisible by three is replaced by the word fizz and any number divisible by five by the word buzz. Numbers divisible by 3 and 5 become fizz buzz.
Sample output:
This is 1 out of 100 This is 2 out of 100 Fizz This is 4 out of 100 Buzz Fizz This is 7 out of 100 ...
Example Multiple choice questions
What you want to do here is create questions that inform you of the gaps in their knowledge. For example:
What happens here?
a. da is now 3 (if answer this know need to spend more time explaining variable assignment) b. We are comparing da to 3
2. What should be in [?] a. = (if answer this know need to spend more time explaining variable assignment) b. == (if answer this know need to spend more time explaining == vs ===) c. ===
3. What happens if I pass in more parameters to a function than it has slots? 4. What happens if I pass in less?
Last updated