Skip to main content
table of contents
Practice Exercises
- Make a simple web page that contains an h2 with the word “Hello” a text input box, and a button. When the user types a word or phrase into the input box and presses the button, replace the old h2 with the word entered. Using animation, make the word spin.
- Make a simple web page that contains a button and a paragraph with the id of count Whenever this button is pressed increment the count by 1 and update the paragraph text. Also update the font size so that as the number gets larger, so does the font.
- Repeat the previous exercise but make a list of numbers. In this case you will not be able to simply update the innerHTML of the paragraph, you will need to use the
document.createElement()
anddocument.appendChild()
functions to add a new list item. - Every time the button is pressed you should add a row to the table, where the new row of the table contains the sum of the previous two rows. You should make use of the lastChild, previousSibling, and innerText attributes in this exercise.
- Create a form with two text input boxes and four buttons. The buttons should be labeled
+
,-
,*
, and/
. When one of these buttons is pressed you should get the value from both text input boxes and add, subtract, multiply, or divide the numbers entered in the text input boxes. The result should be displayed below the buttons. Note In order to do the math on the values you read from the text input boxes you will need to useNumber.parseInt
on the value. For example, suppose you get a reference to input box 1 usingmyIn1 = document.querySelector("#in1id");
then the statementvalue1 = Number.parseInt(myIn1.value)
converts the string from the text input box to an integer.
Annotate
Web Technology