IT Education Trainer's Session Guide
IT Education Trainer's Session Guide
The IT Education training is officially hosted by the Peer Educators Nework (PEN).
Welcome, dear trainer. This material will be your official guide to training young students in the ITEducation course.
First things first: this material is written for you, the trainer - not for the students. This is why it won't be very
technical thechnology-wise but it will rather be a guide to manage the flow of your training sessions.
The structure of the material is rather simple. Each session in this material you will correspond in a real training
session you will go through in the classroom in chronological order. Each session in this material will be synced with
the students' material and it will contain the key points you have to explain in every subsection. Of course, it will also
contain solved classwork and homework problems.
We require you to read the students' material prior to every session, as well as this material. You also have to go
beyond the material and explain personal experiences, things you've read before, personal projects relevant to the
course, etcetera - anything that keeps the students' attention in the classroom and gets them generally excited about
programming.
Finally, this material is not your holy book. It may lack information, may be misinterpreted, may contain typos, may
be dire, may contain untested code, and may sometimes be vague. It is your job to add your own flavor to every
session and cooperate with this material. Be friendly. Be honest. Be funny. Be supportive.
Here is your first task: If you find typos or anything incorrect or misleading in this material, please email them to:
arditdemolli98@[Link].
1. Introduce yourself
2. Let the students introduce themselves
3. Get the students exited about the course
4. Make a list of rules
5. Theory
6. Break
7. HTML introduction
8. Classwork
9. Create a group chat
10. Assign the homeworks
1. Introduce yourself
Introduce yourself and talk something about your life, what made you start programming, your experience, how did
you become a teacher, etc. Try to have eye contact with all of the students since it is your first interaction with them
and first impression matters.
Tell them what you will offer to them as a trainer, and what you await from them as students.
You can say that you will give your best and you await the same from them.
If they give interesting answers where you think you can interact, go ahead by giving a comment or making a sub-
question. Remember, the more they talk, the more comfortable they will feel.
High wages
Work remotely
Guaranteed job
No need for a degree
Express your creativity
Flexible hours
Explain each of the points mentioned, you can use photos to make it more interesting.
After you talk about all the benefits, you can show on screen this meme:
It is a good practice to make the students laugh sometimes to get their attention and make them feel comfortable
with you.
4. Make a list of rules
Because the training will last two months long and it's a quite a time, it is good to set some basic rules in order to
have the best experience. Make the list of rules together with the group.
Start by adding rule number 1 in the table which can be a word or a short sentence like "Respect each other".
Ask them for rules to write, if they don't give answers you can add one more, like "Help each other".
Repeat the process until you have a list with rules that looks something like this:
You can first write the list on the white board and in a big paper after, make sure to write it beautiful and clean then
hang the paper on the front wall where everybody can see it. The rules have to be followed by everyone fom that
moment on.
5. Theory
After doing the presentation part and setting the rules now it's time to start.
The things that you will discuss are related to the student's manual.
Applications that are run in the browser are called Web applications.
HTML - (Hyper Text Markup Language) which is responsible for the structure of a website.
CSS - (Cascading Style Sheet) which is responsible for the aesthetics and the visual appeal of a website.
Make connections between client side devices and server side devices with frontend and backend. Tell them that
someone who codes in frontend is called a frontend Web developer, someone who codes in backend is called a
backend Web developer and someone who codes in both frontend and backend is called a full stack web developer.
Now tell them that at the end of the training they will become frontend Web developers.
6. Break
Take a 15 minute break.
7. HTML introduction
HTML (Hyper Text Markup Language) is a markup language used for structuring and presenting Web page content.
You can explain HTML to the students based in the students manual, but also go beyond it by giving more examples
and making constantly questions about the things that you are talking to make sure that everyone is on track.
You can show a photo like this on screen and simplify the html element's structure to them.
Make sure that the students understand exactly the purpose of html. Note to them that every element has a
meaning, and show them how you choose which tag when to use.
Talk a bit more about the semantic meaning and importance of html tags.
Now before you start writing html, explain the students the tools that are used to write code (code editors) and
mention some of them. Go ahead by using VS Code and teach them how to create an html file and save it. Explain by
using examples:
paragraphs
headings
ordered and unordered lists
Make sure to explain to them that the headings should be chosen not because of the size of the content, but
because of the importance of it. A page should only have one h1. Explain how this affects the SEO and Web
Accessibility.
8. Classwork
Exercise 1.1
Put a picture of a newspaper on the screen and identify the headings and the paragraphs together with the
students. You can use the photo of the newspaper from the students manual.
Answer
The title "The Daily Telegraph" is a heading 1 because it is the most important information, other titles and subtitles
can be h1, h2, ..., h6 and the text under the titles are paragraphs. Ignore the images. And note that the styling is
done by using CSS.
Exercise 1.2
The students have to copy the text by their manuals under the section "Classwork material" which is at the end and
paste it in the editor, after that they have to wrap the text in html tags, using headings, paragraphs and lists.
Answer:
span
strong
em
pre
There are many other, but search about these tags online and use them in the first exercise.
Give them some extra explanation and tips about the homeworks and tell them what to do after they finish.
Session 2 - Basic HTML
Plan
1. Last session summary
2. HTML document structure
3. More HTML elements
4. The anchor tag
5. Classwork
6. Break
7. Self closing tags, emphasize img
8. Talk about attributes
9. Assign the homeworks
Now ask the students what is a web application and what are the involved technologies in it. After they give you an
answer show this image on the screen and ask them what does each of the languages do.
Now focus on html and ask them how do we write html, after getting an answer show to them this image and ask
explain one more time the html element.
Note
The idea of the repetition is to have interactivity with the students, however there is a possibility that they don't
know any of the questions you asked, so it is your duty to answer to all of them with better examples so this time
they won't forget them.
</head>
<body>
</body>
</html>
<strong>
<em>
<blockquote>
<cite>
<pre>
Use the same examples that are in the student's manual, or create some other examples to make everything more
understandable to the students.
Break
Take a 15 minute break.
This is going to be the most important tag in this part. Talk about the <img> tag and explain it with examples, use
the attributes of the img tag as well (src, alt, width, height) and explain how they all work. Download some images
and explain how you would write the src of a local image.
We recommend you to look at the explanation and examples in the students manual.
Classwork
Exercise 2.1
Use the last exercise from the last session, but now the students have to use the new tags they learnt. Show them
how the result should look in the browser and give them up to 15 minute to solve it. Instruct them to download a
photo and insert it.
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Recipes</title>
</head>
<body>
<h1>BBQ Ranch Chicken Tacos</h1>
<img alt="BBQ ranch chicken tacos photo" src="[Link]">
<h5>Recipe by John Doe</h5>
<h2>Ingridients:</h2>
<ul>
<li>Tortillas</li>
<li>Chicken (cooked & shredded)</li>
<li>Corn</li>
<li>Black Beans</li>
<li>BBQ Sauce</li>
<li>Ranch Dressing</li>
<li>Optional: French onions</li>
</ul>
<h2>Instructions:</h2>
<ol>
<li>Gather all ingridients</li>
<li>In a bowl add cooked chicken, black beans, corn, BBQ sauce and
ranch
dressing</li>
<li>Mix together well until everything is coated in sauce.</li>
<li>Scoop the mix into tortillas</li>
<li>Sprinkle french onions on top</li>
<li>Enjoy</li>
</ol>
<p><strong>Wash your hands before starting</strong></p>
<p><em>Note: For easy serving, you can prepare the mix ahead of time &
store in a
tupperware. Layer on tortillas when you're ready to serve. To enjoy this
on the
go, use canned or packets of chicken, cans of black beans & corn and
packets of
ranch & BBQ sauce.</em></p>
</body>
</html>
Tell them which of the elements we used until now are inline-level and which block-level.
Start with <div> and <span> , mention the main difference between these two tags (one is block-level the other
inline-level) use them in an example.
Now make the difference between generic containers and semantic containers and continue with the semantic
containers.
Since we are going to use semantic tags during the whole course you need to explain every semantic container to
them carefully. You can find a good explanation in the student's manual.
Classwork
Exercise 3.1
Identify the containers such as: header, nav, main, section, article, aside, footer, etc. in a Webpage like BBC.
Answer
Identify all the elements, even lists, headings, images, paragraphs but emphasize the containers.
Break
Take a 15 minute break.
Tables
First explain to them what tables are in simple words and show them an example. You can say that tables are made
by rows and columns, the first row usually represent's the header of the table that describes the table or the columns
of the table and all the other rows are filled with data and sometimes the last row works as a footer.
Now create a table in HTML and tell them that it won't look good, but you will make it look better when you learn
how to style elements in CSS.
Classwork
Exercise 3.2
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Exercise 3.2</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>John</td>
<td>34</td>
<td>New York</td>
</tr>
<tr>
<td>Mark</td>
<td>22</td>
<td>Berlin</td>
</tr>
<tr>
<td>Jane</td>
<td>27</td>
<td>Vancouver</td>
</tr>
</table>
</body>
</html>
Because this is a complex table you will be provided with some instructions.
<style>
th,td{border: 1px solid black}
</style>
2. Add this attribute inside the opening tag of the table: cellspacing="0"
3. Use thead to wrap first two rows, use tbody to wrap the third, fourth and fifth rows and use tfoot
to wrap the last three rows.
4. Use divs inside the <td> tags of the second row, to seperate the text in new lines.
The solution:
<!DOCTYPE html>
<html>
<head>
<title>Homework 3.2</title>
<style>
th,
td {
border: 1px solid black;
}
</style>
</head>
<body>
<table cellspacing="0">
<caption>Complex Table</caption>
<thead>
<tr>
<td colspan="3">Invoice #123456789</td>
<td>14 January 2015</td>
</tr>
<tr>
<td colspan="2">
<div><strong>Pay to:</strong></div>
<div>Acme Billing Co.</div>
<div>123 Main str.</div>
<div>Cityville, NA 12345</div>
</td>
<td colspan="2">
<div><strong>Customer:</strong></div>
<div>John Smith</div>
<div>321 Willow Way</div>
<div>Southeast Massachussets, MA 54321</div>
</td>
</tr>
</thead>
<tbody>
<tr>
<th>Name/Description</th>
<th>Qty.</th>
<th>@</th>
<th>Cost</th>
</tr>
<tr>
<td>Paperclips</td>
<td>1000</td>
<td>0.01</td>
<td>10.00</td>
</tr>
<tr>
<td>Staples (box)</td>
<td>100</td>
<td>1.00</td>
<td>100.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="3">Subtotal</th>
<td>110.00</td>
</tr>
<tr>
<th colspan="2">Tax</th>
<td>8%</td>
<td>8.80</td>
</tr>
<tr>
<th colspan="3">Grand Total</th>
<td>$ 118.00</td>
</tr>
</tfoot>
</table>
</body>
</html>
Session 4 - Advanced HTML
Plan
1. Last session summary
2. Forms
4. Fieldset element
5. Break
6. Videos
7. Audios
You can track their progress with these questions, if they couldn't answer none of them, you should discuss with
them what to do to get back on track.
Forms
Now first explain the need of forms, let the students know that whenever we give data in a browser there is a
<form> behind written in html. Now show them examples like facebooks login and signup forms, just to show
them what elements can a form contain, like inputs, labels and buttons. Now start by writting a form with two inputs
and a button.
Now explain in details what the attributes of the input mean and how do they affect the input try to explain name
attribute in an easy way. Explain to them that these are all inline elements that's why you used the <br> tag,
remove the <br> tag to let them see how the form would appear.
Now show them a better way of doing this. Add some labels and wrap the labels and inputs in div tags instead of
using <br> .
<form>
<div>
<label for="name">Enter your name: </label>
<input type="text" placeholder="Your name..." name="name" id="name">
</div>
<div>
<label for="email">Enter your email: </label>
<input type="email" placeholder="Your email..." name="email" id="email">
</div>
<div>
<button type="submit">Subscribe</button>
</div>
</form>
Now explain what the label does, why the inputs need to have id-s to work with labels, what kind of types can a
button have (submit, button, reset), etc.
After you've done explaining them all, show them an example by using some of the input types that will be mostly
used by creating a more complex form.
<form>
<div>
<label for="username">Username: </label>
<input type="text" placeholder="Username here..." name="username"
id="username">
</div>
<div>
<label for="email">Email: </label>
<input type="email" placeholder="Email here..." name="email" id="email">
</div>
<div>
<label for="dob">Date of birth: </label>
<input type="date" name="dob" id="dob">
</div>
<h2>Favorite language</h2>
<div>
<input type="radio" name="fav-lang" id="html" value="html">
<label for="html">HTML</label>
</div>
<div>
<input type="radio" name="fav-lang" id="css" value="css">
<label for="css">CSS</label>
</div>
<div>
<input type="radio" name="fav-lang" id="javascript" value="javascript">
<label for="javascript">JavaScript</label>
</div>
<h2>Select only the car brands</h2>
<div>
<label for="bmw">BMW</label>
<input type="checkbox" name="terms" id="bmw" value="bmw">
</div>
<div>
<label for="msoft">Microsoft</label>
<input type="checkbox" name="terms" id="msoft" value="msoft">
</div>
<div>
<label for="nbullet">Nutribullet</label>
<input type="checkbox" name="terms" id="nbullet" value="nbullet">
</div>
<div>
<label for="comment">Leave a comment: </label>
<textarea name="comment" id="comment" cols="30" rows="10"></textarea>
</div>
<div>
<label for="password">Password: </label>
<input type="password" placeholder="Password here..." name="password"
id="password">
</div>
<div>
<button type="submit">Subscribe</button>
</div>
</form>
This is just an example of a more complex form, you can use other input types as well, after you've done with most of
the input types show them the fieldset element.
<form>
<div>
<label for="username">Username: </label>
<input type="text" placeholder="Username here..." name="username"
id="username">
</div>
<div>
<label for="email">Email: </label>
<input type="email" placeholder="Email here..." name="email" id="email">
</div>
<div>
<label for="dob">Date of birth: </label>
<input type="date" name="dob" id="dob">
</div>
<fieldset>
<legend>Favorite language</legend>
<div>
<input type="radio" name="fav-lang" id="html" value="html">
<label for="html">HTML</label>
</div>
<div>
<input type="radio" name="fav-lang" id="css" value="css">
<label for="css">CSS</label>
</div>
<div>
<input type="radio" name="fav-lang" id="javascript" value="javascript">
<label for="javascript">JavaScript</label>
</div>
</fieldset>
<fieldset>
<legend>Select only the car brands</legend>
<div>
<label for="bmw">BMW</label>
<input type="checkbox" name="terms" id="bmw" value="bmw">
</div>
<div>
<label for="msoft">Microsoft</label>
<input type="checkbox" name="terms" id="msoft" value="msoft">
</div>
<div>
<label for="nbullet">Nutribullet</label>
<input type="checkbox" name="terms" id="nbullet" value="nbullet">
</div>
</fieldset>
<div>
<label for="comment">Leave a comment: </label>
<textarea name="comment" id="comment" cols="30" rows="10"></textarea>
</div>
<div>
<label for="password">Password: </label>
<input type="password" placeholder="Password here..." name="password"
id="password">
</div>
<div>
<button type="submit">Subscribe</button>
</div>
</form>
Break
Take a 15 minute break.
Video
You can look at the student's manual and check mdn as well for the video tag, mention what the attributes do. Don't
forget to download some videos before just to make some examples
Audio
Let them know that video and audio work the same, check about audio in the same sources as for the video
(student's manual and mdn). Download some audios before, so you can create examples with them.
Assign homeworks
1. Create a page that has a nav with a list in it. The list must have 3 list items, one should be "Recipe exercise",
the other "Form exercise" and the last one "Video and Audio exercise".
All of the list items should be wrapped in anchor tags, the first one should redirect you in the last exercise
where we did the recipe, the second one should redirect you in a page with just a form and some inputs in
it (try to use as many input types as you can) and the last one should redirect you in a page with a video
and an audio (choose whatever video and audio you want).
Session 5 - git and GitHub
We wanted students to have a good workflow in the classroom and in their homes. This is why we came up with the
following idea: All students will have a folder called Name_Surname on their classroom laptops which is synced to a
remote repository on GitHub. In this way they can clone the repo at their house and have everything right where
they left off.
The goal of this session is for students to understand the basics of Git and GitHub and also set up their workflow.
There is no need to go into complicated commands (even branching, for that matter) but to simply understand
commits and remote repositories.
Installing Git
If Git is not already installed in the students' machines, you should install it with them. This should take very little
time.
A key thing to focus in this section is that you should use the Command Line and not any GUI tool. In this way the
students won't get scared of the command line and understand it accomplishes the same things as a GUI.
Exercise 5.1
Create a folder on the Desktop with the name Name_Surname. Initialize this as a git repository. Create an empty
file called [Link]. Add this change to the Staging Environment. Commit this change with the message "Created
the file where the book will be written".
Solution
After commiting the new file, as in the student material, you can go through the next exercise.
Exercise 5.2
Let's try commiting more. Add the line "Spiderman is the greatest hero of all time." to the [Link] file. Commit this
change as "Added Spiderman as main character".
Change the line in the file to "Superman is the greatest hero of all time.". Commit this change as "Changed main
character to Superman". Do this with a couple more superheroes. Can you print all the commits in the command
line?
Solution
It is simple doing these exercises, however there is one new thing at the end. Namely, the git log command
which prints all of the commits.
Note
Note
The GitHub Desktop application is needed for this exercise. If it is not already installed, you should go through it
with the students.
Exercise 5.3
Publish the repository Name_Surname to your GitHub account as a private repository using GitHub Desktop.
Exercise 5.4
Divide the students into pairs of two. Let them invite each other as collaborators on the GitHub repositories they
just published. After accepting the invites, let them clone each other's repository to their machines using GitHub
Desktop.
Exercise 5.5
While the students are still divided in pairs, do this exercise. Let them make a change to their repositories and
commit it as "I just pushed this!". Then make them push the changes to GitHub. Now, if they and the collaborator
go to GitHub on the website they should see the new commit.
Exercise 5.6
While the students are still divided in pairs, do this exercise. Let the collaborators pull the changes from their
friend's repository and see the change, through git log , on their local copy.
Note
After this exercise is successfully finished, don't forget to tell students remove each other as collaborators and delete
the cloned repositories.
Homework 5
1. Clone the repository Name_Surname on your home PC.
2. Delete the file [Link] commit it as "Cleared the folder". Now push this change to the Remote Repository.
3. Install the GitHub application on your phone so you always have your work with you.
Session 6 - CSS Intro (selectors and specification rules)
Plan
1. Last session summary
2. What is CSS
3. Explain inline, internal and external CSS
4. Classwork
5. Break
6. Explain selector combinations
7. Classwork
8. Explain class and id
9. Explain the specification rules
10. Assign the homeworks
If the students don't know the answers, make sure to explain them all again just in short words.
What is CSS
You can describe CSS to them with your own words or check the student's manual, however, at this point only
explain them what CSS does, how it works, and how we write it.
You can show an image like this so you can define easily a css rule:
Inline, internal, external CSS
Now make examples with all three ways of writting CSS starting by inline and internal, but focus on showing them
the benefit of using external CSS.
Classwork
Exercise 6.1
The students have to create a css file and link it with the following html document.
<!DOCTYPE html>
<html>
<head>
<title>Exercise 6.1</title>
</head>
<body>
<h1>The most important information</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit facilis
eum veniam ratione harum qui!</p>
<h2>Another heading</h2>
</body>
</html>
Break
Take a 15 minute break.
Selector combinations
Show to the students how we can use combinations for targeting a specific element or group of elements in the
selector. You can check the student's manual and use the same examples or create your own if you want to. It is
important to use semantic containers and elements like we have been using until now.
You can explain a bit more how the siblings relationship works by giving more complex examples.
Example:
<h2>First heading</h2>
<h2>Second heading</h2>
<h2>Third heading</h2>
<p>Fourth should appear</p>
<h2>Fourth</h2>
<p>Fifth too</p>
<h2>fifth</h2>
Now you can tell them which element would get targeted if we write combinations like these:
h2 + h2 {
color:red;
}
p + h2 {
color:blue;
}
p + h2 + p {
color: pink;
}
h2 + p + h2 {
color: tomato;
}
Classwork
Exercise 6.2
Like in the last exercise, the students have to create a css file and link it to the following html document.
<!DOCTYPE html>
<html>
<head>
<title>Exercise 6.1</title>
</head>
<body>
<header>
<h1>Webpage Title</h1>
<nav>
<ul>
<li>Home</li>
<li>News</li>
<li>About</li>
</ul>
</nav>
</header>
<main>
<h2>Latest</h2>
<article>
<h3>Lorem ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit
facilis eum veniam ratione harum qui!</p>
</article>
</main>
<section>
<article>
<h3>Yesterday</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit
facilis eum veniam ratione harum qui!</p>
</article>
</section>
<footer>
<p>All rights reserved by IT Education</p>
</footer>
</body>
</html>
Class and id
Now use the examples that you have worked on until now, just add some classes or id to the elements and target
them by their classname or id.
Take some examples like the ones in the student's manual to explain when they can override something and when
not.
Try to learn them by the beginning to avoid the use of inline css, !important and id's. Recommend the use of classes
for styling.
Assign homeworks
1. Create the proper structure of an html document and add the code below to the body.
<h1>Most important</h1>
<nav>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
</nav>
<section>
<h2>Section heading</h2>
<article>
<h2>Heading inside article</h2>
<p>This is a paragraph inside article</p>
</article>
</section>
<section>
<h2>Another heading</h2>
<blockquote>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Recusandae velit
veniam eius laboriosam. Iusto, eos!
</blockquote>
<cite>John Doe</cite>
</section>
2. Now create an external css file and link it with the html document.
3. Finish the following tasks:
align the h1 to center and make it's color darkblue
make the second and third list item red
change the color of h2's inside section to lightblue
change the color of the h2's inside article to cyan
use the "all" selector, to align all element's inside section to center
4. Now create a new css file and link it with the same document.
5. You have to do the same tasks, but now give to the elements in html some classes and target them only by
classes in css
Session 7 - Background, Size, Units and Colors
Plan
1. Last session summary
2. The background property
3. The height and width properties
4. Classwork
5. Break
6. RGB and RGBA
7. Assign the homeworks
What is CSS?
How can we write CSS and which is the prefered way?
What is a CSS rule, declaration block, declaration, property, value?
What is the property for changing text color?
What is the property for aligning text?
Show them images of selectors like these and ask them what they mean:
For the end show them the specificity points table and see if they understand it.
If the students don't know the answers, make sure to explain them all again just in short words.
Whenever you make examples with images, it is good to use photos from internet, but also from your local storage.
Make sure that they understand exactly how % , vh and vw work since these are relative units and help us create
responsive Webpages.
Classwork
Exercise 7.1
<!DOCTYPE html>
<html>
<head>
<title>Exercise 7.1</title>
</head>
<body>
<header>
<h1>Page Logo</h1>
<nav>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Section heading</h2>
<article>
<h2>Heading inside article</h2>
<p>This is a paragraph inside article</p>
</article>
</section>
<section>
<h2>Another heading</h2>
<blockquote>
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Recusandae velit veniam eius laboriosam.
Iusto,
eos!
</blockquote>
<cite>John Doe</cite>
</section>
</main>
<footer>
<p>Copyrights reserved to ...</p>
</footer>
</body>
</html>
Tasks:
Give a background color to the body
Give a background color to the header
Give a background image to the main
Give a background color to the footer
Give different background colors to the sections
The header should occupy 15% of the height of the viewport
The main should occupy 70% of the height of the viewport
The footer should occupy 10% of the height of the viewport
The blockquote should occupy 20% of the width of the section
The headings of the sections should be in the center
Break
Take a 15 minute break.
RGB and RGBA
Here you will explain how RGB and RGBA work, you can check the student's manual, there are some examples, but
you can go ahead and create your own examples too.
Best way to explain rgba is to put a background image so the transparency will be obvious.
Learn them how to use a color picker tool online, so they will have an easier time with the colors.
Use whatever photo you want for the background of <main> and use a color picker to find the values of the colors
I used in rgb. The background color of the elements inside <main> is done with rgba.
Note:
This is not a goodlooking or a meaningful page, the idea here is to use all the properties and values that we learned
in css. If you want to add meaningful content and make it look better, go ahead.
Session 8 - Typography, The Box Model and Display
Plan
1. Last session summary
2. Typography
3. The Box Model
4. Break
5. Classwork
6. Display inline, block, inline-block
7. Assign the homeworks
Typography
You can read from the student's manual about the theory, there is a ton of information about typography.
You can write some headings and parahraphs to manipulate with different properties and create examples for
typography.
There are some examples on the student's manual that you can use.
Break
Take a 15 minute break.
Classwork
Exercise 8.1
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blank Template</title>
</head>
<body>
<h1>Make this text blue, underlined, and have a gold background</h1>
<h2>Make this text purple, bolded, 25px, and hav an orange border </h2>
<section>
<p>Make this section width of 50%, height of 200px, background of gray,
border of black, and the paragraph text white</p>
</section>
<footer>
<h3>Make this footer have a black background, with light green border,
and this text 20px white plus a font-family of Roboto</h3>
</footer>
</body>
</html>
All the tasks the student's have to do are inside the text tags in the html code above.
Display
For the display property, first mention only the values that the student's are already aware that exist (inline and
block).
Display inline-block will be the highlight of this part, so focus more on it. You can create a simple navbar just to give
them the idea how inline-block works and this will help them with the homework.
Position relative
You can use the examples that are in the student's manual to present position relative.
Position absolute
You can use the examples that are in the student's manual to present position absolute. Make sure to explain the z-
index and transform: translate property to them properly, and how the position absolute takes the element out from
the webpage flow.
Classwork
Exercise 9.1
Create 5 boxes using div tags, give them a height, a width and a color just so they can be seen. Now position 4 of the
boxes on each corner of the page and the fifth box in the middle.
Break
Take a 15 minute break
Flexbox
In this part focus only on showing them the benefits of using flexbox. Since flexbox has more properties to use, in
this session use only properties on flex containers and not flex items. There are some examples on the student's
manual, however you can use some other examples too
Note
Since this is the first time of doing an exercise like the second one, we don't expect you to make it 100%, but try
your best.
Session 10 - Flexbox and Responsive Web
Plan
1. Last session summary
2. Flex items and properties
3. Classwork
4. Responsiveness
5. Break
6. Media queries
7. Assign the homeworks
When we have position set to relative, based on what do top, right, bottom and left properties work?
When we have position set to absolute, based on what do top, right, bottom and left properties work?
What is the z-index?
What properties do we use to set an element in the middle of the page?
What is a flex container?
What properties do we use to position items on a flex container?
For example:
<ul>
<li><a href=#>Home</a></li>
<li><a href=#>Portfolio</a></li>
<li><a href=#>About</a></li>
<li><a href=#>Contact</a></li>
</ul>
If we set here the ul to display:flex; only the li 's are considered flex items and not the anchors inside
them.
The best way to explain flexbox is by creating some empty boxes using div tags and then manipulating with them
just to show the students how every property works. In the future sessions you will be working more complex layouts
with meaningful content using flexbox.
Here is an example of the use of some flexbox properties with dummy items
<!DOCTYPE html>
<html>
<head>
<title>Flex Box</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.1">
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="container">
<div class="item item-1">1</div>
<div class="item item-2">2</div>
<div class="item item-3">3</div>
<div class="item item-4">4</div>
</div>
</body>
</html>
.container{
margin:50px;
padding:15px;
background-color: gray;
display: flex;
flex-direction:row;
height:600px;
align-items:flex-start;
justify-content: space-between;
flex-wrap:wrap;
align-content: space-between;
}
.item{
font-size: 30px;
background-color: red;
padding:15px;
margin:10px;
flex-grow:1;
}
.item-1{
flex-basis:75%;
order:3;
}
.item-2{
order:0;
}
.item-3{
order:1;
flex-basis:25%
}
.item-4{
order:2;
}
You can add more div tags to demonstrate the use of different properties.
Classwork
The students have to finish all the levels in Flexbox Froggy.
Web Responsiveness
There is a lot of theory in the student's material, show them how web responsiveness came as an idea and it's
importance.
Mention fluidity, elasticity and content decision and tell them in short words what they mean.
You can show examples of responsive websites online, for example: BBC, Techcrunch, etc.
Break
Take a 15 minute break
Media queries
Explain how media queries work, how we set the size of the viewport and everything.
Don't forget that an important part for media queries to work is to set it up first inside <head> with the meta tag
<meta name="viewport" content="width=device-width, initial-scale=0.1"> . Create examples
with boxes by changing their size or color on different viewport sizes.
For example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive web</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="wrapper">
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
</div>
</body>
</html>
.wrapper {
display: flex;
justify-content: space-around;
}
.box {
width: 200px;
height: 200px;
background-color: #1e1e1e;
border: 1px solid red;
}
Display grid
You can find plenty information about grid in the students material with examples as well.
The best way of demonstrating all the properties is just by creating some empty boxes and moving them around
using different properties and values. Explain to the students how fractions work in a simple way.
After this you can create an easy layout that is in the students material by using grid. There is also the code added.
Open inspect element and show the students how grid appears, also it is very common to make mistakes when
using: grid-column and grid-row to set the grid items positioning, so the easiest way is to check with inspect
element.
Now they will know better how to use these properties and not mess up the whole layout.
Classwork
The students have to create the layout below using grid, instruct them to make a grid with 12 columns and 12 rows
so they can be more flexible on how long or wide they want their elements to appear.
The answer:
<!DOCTYPE html>
<html>
<head>
<title>Grid View</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.wrapper {
margin: 0;
padding: 10px;
height: 100vh;
color: red;
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: repeat(12, 1fr);
grid-gap: 5px;
}
section,
nav,
main,
aside,
header,
footer {
border: 2px solid red;
border-radius: 5px;
padding: 15px;
}
header {
grid-column: 1 / -1;
}
.sidebar {
grid-column: 1 / 3;
grid-row: 2 / 12;
}
nav {
grid-column: 3 / 11;
}
main {
grid-column-start: 3;
grid-column-end: 11;
grid-row-start: 3;
grid-row-end: 12;
}
aside {
grid-column-start: 11;
grid-column-end: 13;
grid-row-start: 2;
grid-row-end: 12;
}
footer {
grid-column-start: 1;
grid-column-end: 13;
}
</style>
</head>
<body>
<div class="wrapper">
<header>Header</header>
<section class="sidebar">Sidebar</section>
<nav>Navigation</nav>
<main>Main</main>
<aside>Ads</aside>
<footer>Footer</footer>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Grid View</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.wrapper {
padding: 10px;
height: 100vh;
color: red;
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: repeat(12, 1fr);
grid-gap: 5px;
grid-template-areas:
"h h h h h h h h h h h h"
"s s n n n n n n n n a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"s s m m m m m m m m a a"
"f f f f f f f f f f f f";
}
section,
nav,
main,
aside,
header,
footer {
border: 2px solid red;
border-radius: 5px;
padding: 15px;
}
header {
grid-area: h;
}
.sidebar {
grid-area: s;
}
nav {
grid-area: n;
}
main {
grid-area: m;
}
aside {
grid-area: a;
}
footer {
grid-area: f;
}
</style>
</head>
<body>
<div class="wrapper">
<header>Header</header>
<section class="sidebar">Sidebar</section>
<nav>Navigation</nav>
<main>Main</main>
<aside>Ads</aside>
<footer>Footer</footer>
</div>
</body>
</html>
Break
Take a 15 minute break.
Answer
footer{
grid-column: 4 / -1;
}
}
@media only screen and (max-width: 600px) {
.wrapper{
gap: 20px;
}
nav{
grid-column: 1 / -1;
}
.sidebar{
grid-column: 1 / 13;
grid-row: 10 / 11;
}
main{
grid-column: 1 / -1;
grid-row: 3 / 10;
}
aside{
grid-row: 11 / 12;
grid-column: 1 / 13;
}
footer{
grid-column: 1 / -1;
}
}
After creating the front-page together with them, their homework will be to create another page of the website.
File organization
Start by creating a folder for the project, and create seperate folders in it for images, css and javascript. You can even
create an html folder if you want.
[Link]
Now all the css that is applied by the browser, will be removed (all paddings, margins will be removed, the text will
look all the same, the headings will be no longer bold and big, etc.).
Tell them that they have two ways of using Bootstrap, via download and via CDN, but don't spend time on teaching
them how to download and install Bootstrap, instead use the CDN.
You can first demonstrate components that we have been using until now, like navbars, tables, forms, cards,
containers, etc. and demonstrate some fancier components like modals and carousels after.
Create a simple website that includes only CSS, without bootstrap and looks beautiful.
Since we are going to teach them Bootstrap only in this session, it is good to focus on teaching them how to use the
Bootstrap documentation to find all the things they need.
Now give them a short explanation about Javascript. You can define it as: A high-level, object-oriented programming
language.
You can read the theory in the students material for a deconstrunct of this sentence.
Explain to them how important is a programming language to the computer and make them exited about Javascript.
Now open the browser and type some Javascript in the console in inspect. You can type something fancy just to
show them some basic functions of javascript, like this:
Don't waste time on explaining them in details what you did here, you can explain in short terms though.
You will be using console log to teach the students the basics of javascript. So start by displaying something like
hello world in the console again, but this time from the browser.
[Link]("Hello world");
[Link](40 + 16 - 10);
[Link](40 + 16 * 7 / 10);
[Link]("John Doe");
Explain how variables work, by storing some values in variables and then referencing them with console log.
[Link](firstName);
[Link](lastName);
Tell them about naming of variables, you can check the students material about this.
Data Types
Here you will have to explain the data types and how to check them using the typeof operator.
Basic operators
Create examples by using the basic operators which are:
aritmetic operators
assignment operators
comparison operators
// Basic Operators
// Math operators
const now = 2022;
const ageJohn = now - 1991;
const ageJeniffer = now - 2018;
[Link](ageJohn, ageJeniffer);
// Assignment operators
let x = 10 + 5; // 15
x += 10; // x = x + 10 = 25
x *= 4; // x = x * 4 = 100
x++; // x = x + 1
x--;
x--;
[Link](x);
// Comparison operators
[Link](ageJohn > ageJeniffer); // >, <, >=, <=
[Link](ageSarah >= 18);
Classwork
Mark and John are trying to compare their BMI (Body Mass Index), which is calculated using the formula: BMI = mass
/ height ** 2 = mass / (height * height). (mass in kg and height in meter).
TEST DATA 1: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall.
TEST DATA 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 m tall.
GOOD LUCK 😀
Answer
if/else statement
You can explain if/else your own way or check the students manual, there are also examples in it.
2. Calculate both their BMIs using the formula (you can even implement both versions)
3. Create a boolean variable 'markHigherBMI' containing information about whether Mark has a higher BMI
than John.
4. Print a nice output to the console, saying who has the higher BMI. The message can be either "Mark's BMI is
higher than John's!" or "John's BMI is higher than Mark's!"
5. Include the BMI values in the outputs. Example: "Mark's BMI (28.3) is higher than John's (23.9)!"
TEST DATA 1: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall.
TEST DATA 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 m tall.
GOOD LUCK 😀
Answer
// type conversion
const inputYear = '1991';
[Link](Number(inputYear), inputYear);
[Link](Number(inputYear) + 18);
[Link](Number('John'));
[Link](typeof NaN);
[Link](String(24), 24);
// type coercion
[Link]('I am ' + 24 + ' years old');
let width;
if (width) {
[Link]('Width is defined');
} else {
[Link]('Width is UNDEFINED');
}
// Use prompt only for example purposes to let the students know that the value that
comes from the input is always a string, you should also store the result in a
variable, like in the comment below
Logical operators
// Logical Operators
const hasDriversLicense = true; // A
const hasGoodVision = true; // B
Classwork
There are two gymnastics teams, Dolphins and Koalas. They compete against each other 3 times. The winner with the
highest average score wins the trophy!
1. Calculate the average score for each team, using the test data below
2. Compare the team's average scores to determine the winner of the competition, and print it to the console.
Don't forget that there can be a draw, so test for that as well (draw means they have the same average
score).
3. BONUS 1: Include a requirement for a minimum score of 100. With this rule, a team only wins if it has a
higher score than the other team, and the same time a score of at least 100 points.
HINT: Use a logical operator to test for minimum score, as well as multiple else-if blocks 😉
4. BONUS 2: Minimum score also applies to a draw! So a draw only happens when both teams have the same
score and both have a score greater or equal 100 points. Otherwise, no team wins the trophy.
TEST DATA: Dolphins score 96, 108 and 89. Koalas score 88, 91 and 110
TEST DATA BONUS 1: Dolphins score 97, 112 and 101. Koalas score 109, 95 and 123
TEST DATA BONUS 2: Dolphins score 97, 112 and 101. Koalas score 109, 95 and 106
GOOD LUCK 😀
Answer
// BONUS 1
const scoreDolphins = (97 + 112 + 80) / 3;
const scoreKoalas = (109 + 95 + 50) / 3;
[Link](scoreDolphins, scoreKoalas);
let drink2;
if (age >= 18) {
drink2 = 'wine 🍷';
} else {
drink2 = 'water 💧';
}
[Link](drink2);
1. Your task is to caluclate the tip, depending on the bill value. Create a variable called 'tip' for this. It's not
allowed to use an if/else statement 😅 (If it's easier for you, you can start with an if/else statement, and
then try to convert it to a ternary operator!)
2. Print a string to the console containing the bill value, the tip, and the final value (bill + tip). Example: 'The
bill was 275, the tip was 41.25, and the total value 316.25'
HINT: To calculate 20% of a value, simply multiply it by 20/100 = 0.2 HINT: Value X is between 50 and 300, if it's >=
50 && <= 300 😉
GOOD LUCK 😀
Answer
Functions
You can describe functions as machines that are programmed to do something.
Let the students know that we were using build-in functions before, for example [Link]() which logs
something to the console or Number() which converts a value to number data type, String() , etc., but now
we are going to create our own functions.
function logger(){
[Link](“Hello world”);
}
logger();
After they understand how it works, you can move on with functions with parameters. For example you can create a
fruit processor function like this:
Explain that by using the return keyword we can produce a value from the function and we can capture this value in a
variable after (eg. orangeJuice and appleJuice).
The words apples and oranges are called parameters which act like placeholders to describe the values that we
should put in the function to be processed.
After understanding this one too, you can go ahead and explain to them other variations for writing functions.
// Arrow function
nutribullet3 = (apples, oranges) => {
const juice = `Juice with ${apples} apples and ${oranges} oranges.`
return juice;
}
Now the difference between writing the function as a declaration and as an expression is that:
[Link](ageJohn);
// This works perfectly fine
[Link](ageJohn);
// This will throw an error
As for the arrow functions you can show them how to write a one line function like this:
[Link](findYearsUntilRetirement(1991, 'John'));
[Link](findYearsUntilRetirement(1951, 'Jennifer'));
Now there is a problem, the output of the second console log is "Jennifer will be retired in -6 years." and this doesn't
make sense at all, so to fix the problem use an if/else statement inside the function.
[Link](findYearsUntilRetirement(1991, 'John'));
[Link](findYearsUntilRetirement(1951, 'Jennifer'));
Classwork
Back to the two gymnastics teams, the Dolphins and the Koalas! There is a new gymnastics discipline, which works
differently. Each team competes 3 times, and then the average of the 3 scores is calculated (so one average score per
team). A team ONLY wins if it has at least DOUBLE the average score of the other team. Otherwise, no team wins!
1. Create an arrow function 'calcAverage' to calculate the average of 3 scores
2. Use the function to calculate the average for both teams
3. Create a function 'checkWinner' that takes the average score of each team as parameters ('avgDolhins' and
'avgKoalas'), and then logs the winner to the console, together with the victory points, according to the rule
above. Example: "Koalas win (30 vs. 13)".
4. Use the 'checkWinner' function to determine the winner for both DATA 1 and DATA 2.
5. Ignore draws this time.
TEST DATA 1: Dolphins score 44, 23 and 71. Koalas score 65, 54 and 49 TEST DATA 2: Dolphins score 85, 54 and 41.
Koalas score 23, 34 and 27
HINT: To calculate average of 3 values, add them all together and divide by 3 HINT: To check if number A is at least
double number B, check for A >= 2 * B. Apply this to the team's average scores 😉
GOOD LUCK 😀
Answer
// Test 1
let scoreDolphins = calcAverage(44, 23, 71);
let scoreKoalas = calcAverage(65, 54, 49);
[Link](scoreDolphins, scoreKoalas);
checkWinner(576, 111);
// Test 2
scoreDolphins = calcAverage(85, 54, 41);
scoreKoalas = calcAverage(23, 34, 27);
[Link](scoreDolphins, scoreKoalas);
checkWinner(scoreDolphins, scoreKoalas);
Arrays
Arrays are data structures which allow us to store a collection of multiple values under a single variable.
You can first save some values in seperate variables and then explain to them how useful arrays are, for example:
let car1 = 'BMW';
let car2 = 'Audi';
let car3 = 'Volkswagen';
let car4 = 'Tesla';
Now after teaching them how to create an array, go ahead with some basic array operations, like:
targeting an element
finding the length of array
targeting the last element of the array
adding a new element in the array
removing an element from the array
finding the index of an element
checking if an element exists in the array
Targeting an element
You need to explain to them how the indexes work first, that they start from 0 and not from 1. Now use the array you
created before to target some of the elements.
[Link](cars[0]);
[Link](cars[2]);
[Link](cars[3]);
[Link]([Link]);
[Link](cars[[Link]-1]);
[Link]([Link]('Volkswagen'));
[Link]([Link]('Mercedes'));
// The result will be a boolean value
1. Write a function 'calcTip' that takes any bill value as an input and returns the corresponding tip, calculated
based on the rules above (you can check out the code from first tip calculator challenge if you need to). Use
the function type you like the most. Test the function using a bill value of 100.
2. And now let's use arrays! So create an array 'bills' containing the test data below.
3. Create an array 'tips' containing the tip value for each bill, calculated from the function you created before.
4. BONUS: Create an array 'total' containing the total values, so the bill + tip.
HINT: Remember that an array needs a value in each position, and that value can actually be the returned value of a
function! So you can just call a function as array values (so don't store the tip values in separate variables first, but
right in the new array) 😉
GOOD LUCK 😀
Session 18 - Objects and Loops
Homework discussion
Discuss the homeworks of last session and code them together with the students by explaining what you're doing.
Objects
Check the students manual for theory and examples about the objects. As soon as you explain how objects and
properties work, assign them the first classwork and give them 5 minutes time to finish it since it is not a hard one.
Classwork
Exercise 18.1
Write the sentence below, but you have to get the highlighted values from the object, do not write them manually:
Answer
const person = {
firstName: 'John',
lastName: 'Doe',
age: 25,
nationality: 'american',
visitedCountries: ['Spain', 'Germany', 'Italy'],
job: 'programmer'
}
After finishing the first classwork and explaining what object methods are, how we write and how we call them, you
can assign the second classwork to the students and give them around 15 minutes to finish it.
Classwork
Exercise 18.2
Let's go back to Mark and John comparing their BMIs! This time, let's use objects to implement the calculations!
Remember: BMI = mass / height ** 2 = mass / (height * height) (mass in kg and height in meter)
Your tasks:
1. For each of them, create an object with properties for their full name, mass, and height (Mark Miller and
John Smith)
2. Create a 'calcBMI' method on each object to calculate the BMI (the same method on both objects). Store
the BMI value to a property, and also return it from the method
3. Log to the console who has the higher BMI, together with the full name and the respective BMI. Example:
"John's BMI (28.3) is higher than Mark's (23.9)!" Test data: Marks weights 78 kg and is 1.69 m tall. John
weights 92 kg and is 1.95 m tall. GOOD LUCK
Answer
const mark = {
fullName: 'Mark Miller',
mass: 78,
height: 1.69,
calcBMI: function () {
[Link] = [Link] / [Link] ** 2;
return [Link];
}
};
const john = {
fullName: 'John Smith',
mass: 92,
height: 1.95,
calcBMI: function () {
[Link] = [Link] / [Link] ** 2;
return [Link];
}
};
Loops
Check the students manual for theory and examples.
Example
This one can be used as classwork as well.
Assign homework
Let's improve Steven's tip calculator even more, this time using loops!
Your tasks:
GOOD LUCK
Answer
getElementById()
querySelector()
querySelectorAll()
You can show to them how HTML and CSS is written in that game, but don't spend much time doing that, since the
idea is to work with Javascript and DOM here.
Now build the game logic along with them by explaining everything.
Classwork
The students have to programm the 'try again' button in the game, so that when they press it, the game should be
restarted in the begining state, except the highscore that changes only if they get a better score or refresh the page.
make it so when the user reaches score 0, the message will say "💥 Game over" and the button will switch
from "Check" to "Try again"
clean the code by creating functions, using ternary operators, variables or whatever you think makes the
code more optimized
Answer
You can find the file named [Link] in the game folder (the path is guess_my_number/js/[Link] ).
Session 20 - Javascript - How to build a carousel
In this session you will teach the students how to create a carousel from scratch, using HTML, CSS and Javascript. You
can send the HTML and CSS code to the students and explain some details to them, like:
They will have the opportunity to learn the classList method by doing this exercise and use concepts like functions,
arrays, loops to interact with HTML elements.
Continue with the Javascript code after, this time you will create functions from the beginning for closing and
opening the modal, so you can call them easily on event listeners.
Session 23 - Javascript - APIs
Since we haven't discussed about concepts like asynchronous and promises before, don't focus on explaining how
the fetch API works in details, instead use this piece of code to experiment with APIs.
You can find in the students material two examples with APIs, so use them to show the students how APIs work.
After finishing these two examples, to make it more interesting you can use NASA APIs to get data direct from NASA
servers.
To use NASA APIs you have to get a key, so, you will need to open an account. However NASA doesn't really care
about the accounts so, if you don't want to give your personal data, you can just fill out the form with random data
to get it.
For example:
name: john
surname: johnson
email: johnjohnson@[Link]
You can copy the URL, which contains the key as well and put it as a parameter in fetch. If the students ask about the
purpose of the key you can explain to them that if you would send millions of requests into NASA's server, they can
stop you by disabling the key you are using.
Now if you scroll down in the NASA Webpage, you can find information about the API, for example if you click on
APOD (astronomy picture of the day)
you can see the documentation and instructions on how to use the API
You will be using the date parameter, which has to be of type YYYY-MM-DD.
Explain to the students that not every Webpage provides you with a good understanding documentation of the API
like NASA does, and that NASA offers only some data for us to use, it doesn't mean that we can use all the data that
is in NASAs servers.
You can log to the console all the data you get back first.
[Link]("button").addEventListener("click", function () {
const choice = [Link]("input").value;
fetch("[Link]
api_key=grrBXEW80QPHXY7UexNYhLUYmcMQ9LWPbnVra5ye")
.then(res => [Link]())
.then(data => {
[Link](data);
})
.catch(err => {
[Link](`error ${err}`);
})
})
After showing them the data in console, you will now create an input with type date and a button so when you
click that button, the API will get triggered.
HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Introduction to APIs</title>
</head>
<body>
<h1>Picture of the day</h1>
<input type="date">
<button>Search</button>
<h2>NASA</h2>
<img src="">
<h4>Explanation</h4>
<script src="[Link]"></script>
</body>
</html>
JS code:
[Link]("button").addEventListener("click", function () {
const choice = [Link]("input").value;
fetch(`[Link]
api_key=grrBXEW80QPHXY7UexNYhLUYmcMQ9LWPbnVra5ye&date=${choice}`)
.then(res => [Link]())
.then(data => {
[Link](data);
[Link]("img").src = [Link];
[Link]("h4").textContent = [Link];
})
.catch(err => {
[Link](`error ${err}`);
})
})
Note how I added another parameter at the end of the url, which is date and we are getting the value from the input.
You can play with it now by changing the date and clicking the button, to show the photo that was taken on that day
by NASA, and the explanation of the photo. However, there are some days that NASA didn't take a picture but took a
video instead, so you can get an error. In this case either try another date, or create an if/else statement to show
videos as well, like this:
[Link]("button").addEventListener("click", function () {
const choice = [Link]("input").value;
fetch(`[Link]
api_key=grrBXEW80QPHXY7UexNYhLUYmcMQ9LWPbnVra5ye&date=${choice}`)
.then(res => [Link]())
.then(data => {
[Link](data);
if(data.media_type === 'image'){
[Link]("img").src = [Link];
} else if(data.media_type === 'video'){
[Link]("iframe").src = [Link];
}
[Link]("h4").textContent = [Link];
})
.catch(err => {
[Link](`error ${err}`);
})
})
Answer
The HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Local Bot Score</title>
</head>
<body>
<button>Another one</button>
<h3>Score</h3>
<span></span>
<script src="[Link]"></script>
</body>
</html>
if () {
[Link]("botScore", 0);
}
[Link]("span").textContent = [Link]("botScore");
[Link]("button").addEventListener("click", anotherOne)
function anotherOne() {
let botScoreVal = [Link]("botScore");
botScoreVal++;
[Link]("span").textContent = botScoreVal;
[Link]("botScore", botScoreVal);
}~
However, there is a Website called [Link] and there you can find an API with all the
functions mentioned above. So, we will be using APIs to get a deck of cards, and to draw two cards randomly. One
card will be for player 1 and the other one will be for player 2. Whoever has the greatest card, wins, if both have the
same card there will be a tie.
We are going to show the pictures of both cards as images, and there will be a message that tells if anyone won or
there was a tie.
We will get the value of the card by using the value property, however for ACE, KING, QUEEN and JACK we have
to manually convert the value to number.
<!DOCTYPE html>
<html>
<head>
<title>Card Game</title>
</head>
<body>
<h1>Card Game!</h1>
<button>Check winner</button>
<h2>Player 1</h2>
<img id="player1">
<h2>Player 2</h2>
<img id="player2">
<h3>Player wins</h3>
<script src="[Link]"></script>
</body>
</html>
[Link]("button").addEventListener("click", drawTwo);
// Drawing two cards and showing them in HTML, together with the winner of the game
function drawTwo() {
const url = `[Link]
fetch(url)
.then(res => [Link]())
.then(data => {
[Link](data);
[Link]('#player1').src = [Link][0].image;
[Link]('#player2').src = [Link][1].image;
let player1Val = convertToNum([Link][0].value);
let player2Val = convertToNum([Link][1].value);
if (player1Val > player2Val) {
[Link]('h3').innerText = "Player 1 wins";
} else if (player1Val < player2Val) {
[Link]('h3').innerText = "Player 2 wins";
} else {
[Link]('h3').innerText = "We have a tie";
}
})
.catch(err => {
[Link](`error ${err}`);
});
}
// Converting ACE, KING, QUEEN and JACK to numbers
function convertToNum(val) {
if (val === 'ACE') {
return 14;
} else if (val === 'KING') {
return 13;
} else if (val === 'QUEEN') {
return 12;
} else if (val === 'JACK') {
return 11;
} else {
return Number(val);
}
}