Exercises
Exercise 1
- Copy/paste the folder
Exercise1fromClassesICTin your personal folder. - Open the file
index.htmlin a browser. - In Notepad++, open the file
main.js. - In
main.js, using the.querySelector()method and the.innerHTMLproperty, change the h1 title toMost popular TV show searches in 2016. - Use the
.getElementById()method and the.innerHTMLproperty to replace the content in the fourth item of the list to:Fourth element. - Style the background-color of the body to
#F9ACB8by using the.styleproperty.
Exercise 2
- Copy/paste the folder
Exercise2fromClassesICTin your personal folder. - Open the file
index.htmlin a browser. - In Notepad++, open the file
main.js.
Let's add a new li element:
- Use the
.createElement()to create a new li and save it in a variable callednewDestination. - Assign to the element an id of
oaxaca. - Assign to the element the text
Oaxaca, Mexico. - Append the new element you created as the last child of the list with the ID
more-destinations. - Scroll to the bottom of the page in the browser to see your new element.
Let’s now delete it:
- Remove the element using the
.removeChild()method and passing in the element with IDoaxaca.
Exercise 3
- Copy/paste the folder
Exercise3fromClassesICTin your personal folder. - Open the file
index.htmlin a browser. -
In Notepad++, open the file
main.js. -
Modify the body of the
turnButtonRed()function so that it modifies the button as follows:- Assigns the
.style.backgroundColortored - Assigns the
style.colortowhite - Modifies the
.innerHTMLtoRed Button
- Assigns the
-
Add interactivity to the button element by adding the function
turnButtonRed()when the button is clicked.
Exercise 4
- Copy/paste the folder
Exercise4fromClassesICTin your personal folder. - Open the file
index.htmlin a browser. - In Notepad++, open the file
main.js. - Access the
.firstChildof the body and save it to a variable namedfirst. Then modify first‘s.innerHTMLto:I am the child!
Take a moment to note which element has now been modified.
- Use the
.parentNodeproperty to access the parent element of the variablefirstand modify its.innerHTMLto:I am the parent and my inner HTML has been replaced!
Take a moment to notice the change in the web page.