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.html
file - Before the closing
</body>
tag, insert a<script>
element with asrc
attribute that specifies the relative path to your JavaScript file (i.e.js/index.js
) - Save and open in your browser
- Open your
index.html
file - Above the
<script>
element, add an empty<footer>
element - Save and refresh your browser
-
Open your
index.js
file -
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:
getFullYear
method
- hint:
-
Using "DOM Selection", select the
<footer>
element from the DOM and store it in a variable namedfooter
- hint:
querySelector
method
- hint:
-
Create a new paragraph (
p
) element and store it in a variable namedcopyright
- hint:
createElement
method
- hint:
-
Set the inner HTML of your
copyright
element to display your name and the current year- hint: use
thisYear
variable from earlier
- hint: use
-
Using "DOM Manipulation", append the
copyright
element to the footer- hint:
appendChild
method
- hint:
-
Save and refresh your browser
- You should see the text "Your Name 2021" at the bottom of the page
- Open your
index.html
file - Above the "Connect" section, add a new
<section>
element with anid
attribute 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.js
file - 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:
querySelector
orgetElementById
method
- 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
for
loop to iterate over yourskills
Array, starting at index 0 - Inside the loop, create a new list item (
li
) element and store it in a variable namedskill
- hint:
createElement
method
- hint:
- On the next line, set the inner text of your
skill
variable to the value of the current Array element- hint: access the Array element using bracket notation
- On the next line, append the
skill
element to theskillsList
element- hint:
appendChild
method
- 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