4. Javascript
Last updated
Was this helpful?
Last updated
Was this helpful?
Students self learn through UDACITY course:
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
2 days (6 sessions, 9hrs)
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 ()
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. ), go over bits that class is struggling with.
At end of wednesday 1 or start of Thursday give them the 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
Datatypes: Cover this sparingly and more through examples. Don't cover bigInt, or the max and min of number (Never hit those limits myself)
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)
Slide deck by emmanuel.
Image on history of JS
Youtube video
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.
Open browser. Press F12. Now have developer console. Can run js code
As a general rule always use === and never ==
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)
The arrow function expression (=>). Very similar to C#
The function invokes as soon as the script is loaded. See it alot in jquery
Scripted but functions get read first so can call them from anywhere in script
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 ...
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?
and
- don't cover switch statement
challenge/ Catch up
. If have time cover Objects too.
Cover getting help: - Stackoverflow - I use this for JS reference
- Chpt 2: JS fundamentals
- Student excerises
My favourite html/js playground. Tons of work people have done