Session Plan
Session Materials
These are some examples of previously created materials by mentors that you can use yourself, or for inspiration.
Session Outline
Function as a variable - function can be called inside another function, like we saw with the homemade
forEachCallback function and asynchronicity - shows a practical example of function that gets called by another function (e.g.
setTimeoutoraddEventListener)
The trainees should after the session feel comfortable with callback functions and the fact that a function works just like a variable that can be passed around. Also asynchronicity is important, when is a function called and where does it stop.
Also hammer in the point of the difference between:
document.querySelector("button").addEventListener("click", logOuttext);
document.querySelector("button").addEventListener("click", logOuttext());Here's a good practical example of callbacks (TODO move this to this repo)
This is super good at explaining function logic
Calling a function within a function
Callback functions
Event Listeners
Anonymous vs named function
Exercises
1. Click counter
Create an index.html file with two buttons:
When the button first is clicked it should first log out 0. The next time it is clicked it should log out 1, etc.
Clicking the second button should also count up and logout the same variable.
2. Delay clicker
Create a button in html with the text "Log in 3 seconds"
When the button is clicked it should wait 3 seconds and then log the text "This text was delayed by 3 seconds".
3. Page onload
First create a callback function as a variable that logs this out: "DOM fully loaded and parsed" This callback function should be called when the DOM is fully loaded. To find what this function is called go to google! What should we search for???
4. Mouse position
Create a handler, that prints the x,y coordinate of the mouse event.
5. Mouse position online tool
Say we want to create an online tool where businesses can see where their users' mouse is most of the time. Businesses can now figure out if they have designed their website correctly.
Let's create some js that will get the average x and y position of a user after 30 seconds.
[!TIP] Before starting with this exercise, create a plan for how you will implement this! Maybe together with your mentor.
Last updated