Javascript - DOM 2
Learning objectives
Input elements
Events expanded
Flipped classroom videos
Teacher instruction
Teach how to get value from different input elements (select, radio, input, etc.)
Plan and create a bad timer app (mvp). Bonus what if the user had to time the timer precisely?
Also show xss
<img src=x onerror=alert("XSS")><img src=x onerror=document.body.style.display="none"><img src=x onerror=alert(document.querySelector(".user-account").innerText)>
Peer instruction
Forms and input elements
Forms are used to send data from the client to a server. Often times you need to write your name, email, telephonenumber etc.
Inputs
Inputs are used to get text from a user. This is how an input is defined 👇 Notice that it is selfclosing! Like the img tag
This is probably the most famous input field ever

There are different types of input fields. One for numbers, text, telephone number, date. See them all here
Checkboxes
Checkboxes are used to get a value that can either be true or false. It is typically used for the remember me functionality

Radio buttons
Radio buttons are used to select between a given set of options.
The label tag shows the text for the radio button. What is important is that the id attribute and the for attribute matched their value. Otherwise the label is not connected to the radio button.
Another important thing is that the groups that are together have the same name attribute

Select
Select is also used to select between a given set of options. It is typically used to select country. The difference from the radio buttons is that in select the user has the possibility to select multiple options!
It is similar to the ul and li. Inside of the select tag there has to be an option tag for each option the user can select. You can give the option tag a value but you dont have to

Buttons
Buttons are used for some kind of interactivity. Should not be used as links!
There are some more form fields but i have covered the most important ones here
Casetime
You can choose between 2 different projects to choose from today or you can use the following prompt to create an project tailored for your level or needs: Remember to insert your interests and difficulty level
Make a plan for how to create this application before you start writing any code. I want to see the plan when i come around!
📝 Online word automatic save functionality - Level 3
When pressing ctrl + s on Office.com in a document, the UI will let you know that it autimatically saves your document. Create that functionality. So when ctrl + s is pressed
one Time, show some text that says "we automatically save your document"
minimum 3 times within 2 seconds show text that says "Wow easy there, we save your document automatically"
The text show be shown, then removed after 2 seconds

Tab countdown timer
https://www.timer-tab.com/
🌍 Personal CO2 Emission Calculator - level 1
Create a web application that allows users to calculate their personal CO2 emissions based on their daily activities. This could be based on the distance they drive, the type of food they consume, their electricity usage, etc.
Maybe a user inputs how many miles they drive in a week and the type of vehicle they own, and the website calculates their weekly CO2 emissions.
Maybe a user inputs the type of food they consume in a week (vegetarian, non-vegetarian, vegan) and the website calculates the CO2 emissions based on their diet.
Maybe a user inputs their monthly electricity bill, and the website estimates their CO2 emissions based on average energy sources.
If you cannot think of any idea, try researching common sources of personal CO2 emissions and see if you can incorporate them into your calculator!
Requirements
The user should input details about their daily activities.
There should be a button that initiates the calculation.
The application should display the calculated CO2 emissions based on the user's input.
📝 Imprecise Calculator - level 3
Create a webapp that works as a calculator. It should be possible for a user to add numbers via buttons as seen in a classic calculator. BUT the calculator should sometimes give a slightly wrong answer.
Advanced:
Make it possible for a user to use the calculator using the keyboard aswell. Remember to foucs on writing good HTML and CSS
If you are unsure how to start then maybe get ChatGPT to help you scaffold this exercise
Please dont make the app make a fart sound when the equal button is clicked!
And please please please dont make the app make different fart sounds when clicking any buttons. It would be childish and it would be below you to create such a feature!
📝 Guess my number - level 3
The project is a game where you have to guess a number. Here are the rules
When clicking the
Check!buttoncheck if what the user wrote in theinputmatches the number they have to guessIf it's wrong increase the Score by 1 and clear the input
If it is correct and smaller than Highscore set the new score as the highscore and clear the input. Also show the correct number in the
?
If the
Againbuttonis clicked clear the score and the highscore and start from scratchAdd a couple of extra features you think could be cool!
The starter for the project can be found here. Create a new project and copy the files into a new project!
Last updated