This assignment will teach you the following:
- What is the DOM?
- Making Changes to the DOM
Merge your pull request from the previous lesson (if you haven't already):
Fetch the updated instructions from the base repository:
Note: you may receive a conflict if you've made changes to the README or other instructions
Checkout your main branch and pull changes:
git checkout main
git pull
Create a new local branch to work on separate from the main branch:
git checkout -b lesson-4-2
Now, open the project directory in your code editor and continue to the next section.
- Create a folder called
js/ - Inside that folder, create a JavaScript file called
index.js - Open your
index.htmlfile - Before the closing
</body>tag, insert a<script>element with asrcattribute that specifies the relative path to your JavaScript file (i.e.js/index.js) - Save and open in your browser
- Open your
index.htmlfile - Above the
<script>element, add an empty<footer>element - Save and refresh your browser
-
Open your
index.jsfile -
Create a new date object and store it in a variable named
today- hint:
new Date()constructor
- hint:
-
Retrieve the current year from your date object and store it in a variable named
thisYear- hint:
getFullYearmethod
- hint:
-
Using "DOM Selection", select the
<footer>element from the DOM and store it in a variable namedfooter- hint:
querySelectormethod
- hint:
-
Create a new paragraph (
p) element and store it in a variable namedcopyright- hint:
createElementmethod
- hint:
-
Set the inner HTML of your
copyrightelement to display your name and the current year- hint: use
thisYearvariable from earlier
- hint: use
-
Using "DOM Manipulation", append the
copyrightelement to the footer- hint:
appendChildmethod
- hint:
-
Save and refresh your browser
- You should see the text "Your Name 2021" at the bottom of the page
- Open your
index.htmlfile - Above the "Connect" section, add a new
<section>element with anidattribute of value "skills" - Inside the new section, add a
<h2>element that says "Skills" - After the
<h2>element, add an empty unordered list (<ul>) element - Save and refresh your browser
- You should see the new "Skills" heading
- Open your
index.jsfile - List your technical skills by creating an Array of String values and store it in a variable named
skills - Using "DOM Selection", select the #skills section by id and store it in a variable named
skillsSection- hint:
querySelectororgetElementByIdmethod
- hint:
- Using "DOM Selection", query the
skillsSection(instead of the entiredocument) to find the<ul>element and store it in a variable namedskillsList - Create a
forloop to iterate over yourskillsArray, starting at index 0 - Inside the loop, create a new list item (
li) element and store it in a variable namedskill- hint:
createElementmethod
- hint:
- On the next line, set the inner text of your
skillvariable to the value of the current Array element- hint: access the Array element using bracket notation
- On the next line, append the
skillelement to theskillsListelement- hint:
appendChildmethod
- hint:
- Save and refresh your browser
- You should see your list of skills beneath the "Skills" heading
Check the status of your local repository to double-check the changes you made:
git status
Stage the file(s) that you edited:
git add .
Check the status again and notice that the changes from before are now staged:
git status
Create a commit for the changes you made and add a message describing the changes you made:
Note: Replace
<message>with your message
git commit -m "<message>"
Push your commit to the remote repository (visible in GitHub):
git push
Check the log to make sure your commit has been published:
git log --oneline
Create a pull request and submit:
Created by Code the Dream
