Session Plan
Conditions
Functions (https://twitter.com/wesbos/status/1105907924088565762)
General description - A function is a reusable piece of code.
Function usage
Arguments
Function creation
Parameters - Acts as placeholders
Parameters vs arguments
Return value - Variable can capture return value.
Calling a function on something
Math.random- calling the function random on Math
Global vs local scope
Lexical scope - inner functions contain the scope of parent functions even if the parent function has returned.
For loop
Try start off with giving the trainees the Exercise string logger and not explain for loop. Let them figure it out through the exercise (problem based learning)
The trainees really struggle with the return value. What it means, how it is captured. What happens when nothing is returned etc. Try really hammering in this concept with lots of simple examples and exercises! e.g. if a function is called get something. That means that something is returned from that function.
Zoey Zou made a nice Notion session plan here: https://www.notion.so/JS1-Week2-8f2d4b7e7ba0425ea4a9e97816e9ceb7
Flipped classroom videos
Code inspiration
if statements
if statementsFunctions
if and function
if and functionScope
for loop
for loopExercises
if statements exercise
if statements exerciseUse if statements to give a user a message based on their bank account balance. Use the balance variable and change that.
If a user has 0 or less balance log out 'Please deposit some money!'
If a user has more than 0 and at most 1000 log out 'Your balance is looking okay'
If a user has more than 1000 and at most 3000 log out 'Your balance is looking good'
If a user has more than 3000 and at most 10000 log out 'Your balance is fantastic'
If a user has more than 10000 log out 'Your balance is AMAZING!'
Function
Create a function called getCircleArea. It should have the radius of the circle as parameter and return the circle area. What happens if we don't return anything in the function?
Create a function called celsiusToFahrenheit it should have a parameter called celsius. It should return the temperature in fahrenheit.
Try call the function and check with google if the function returns the right value.
Exercise: Scope
With pen and paper write what is logged out.
for loop exercises
for loop exercisesSimple for loop
for loopCreate a for loop that logs out the numbers from 74 - 98
for loop in a function
for loop in a functionCreate a function that has two parameters: stringToLog and numberOfTimesToLog
When calling the function it should log out the stringToLog the amount of times specified in numberOfTimesToLog. Use a for loop.
Send emails
Imagine we work at a company. Anna from the HR department wants us to send out a couple of emails to some recipients. The only problem is that she sent us the email in a weird format: [email protected]|[email protected]|[email protected]|[email protected]|[email protected]|[email protected]|[email protected]
Use the sendEmailTo function to send an email to all the recipients that we got from Anna.
Hint use the .split method and look up iterating an array js for loop on google.
Last updated