5. deleteChildElements a. Receives a parentElement as a parameter b. Define a child variable as parentElement.lastElementChild c. While the child exists...(use a while loop) d. Use parentElement.cemoveChild to remove the child in the loop e. Reassign child to parentElement.lastElementChild in the loop f. Return the parentElement

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Ans 5

5. deleteChildElements
a. Receives a parentElement as a parameter
b. Define a child variable as parentElement.lastElementChild
c. While the child exists...(use a while loop)
d. Use parentElement.removeChild to remove the child in the loop
e. Reassign child to parentElement.lastElementChild in the loop
f. Return the parentElement
NOTE: The above functions had no dependency on other functions. They were very
self-contained which is ideal. That is not always possible though. We will try to limit
dependencies as we go. The next several functions have small dependencies.
6. addButtonListeners
a. Selects all buttons nested inside the main element
b. If buttons exist:
c. Loop through the NodeList of buttons
d. Gets the postld from button.dataset.postld
e. Adds a click event listener to each button (reference addEventListener)
f. The listener calls an anonymous function (see cheatsheet)
g. Inside the anonymous function: the function toggleComments is called with the
event and postid as parameters
h. Return the button elements which were selected
i. You may want to define an empty toggleComments function for now. Not all tests
will pass for addButtonListeners until toggleComments exists. I recommend
waiting on the logic inside the toggleComments function until we get there.
7. removeButtonListeners
a. Selects all buttons nested inside the main element
b. Loops through the NodeList of buttons
c. Gets the postld from button.dataset.id
d. Removes the click event listener from each button (reference
removeEventListener)
e. Refer to the addButtonListeners function as this should be nearly identical
f. Return the button elements which were selected
8. createComments
a. Depends on the createElemWith Text function we created
b. Receives JSON comments data as a parameter
c. Creates a fragment element with document.createDocumentFragment()
d. Loop through the comments
e. For each comment do the following:
f. Create an article element with document.createElement()
g. Create an h3 element with createElemWith Text('h3', comment.name)
h. Create an paragraph element with createElemWith Text("p', comment.body)
i. Create an paragraph element with createElemWith Text("p', 'From:
S{comment.email}')
j. Append the h3 and paragraphs to the article element (see cheatsheet)
k. Append the article element to the fragment
I. Return the fragment element
Transcribed Image Text:5. deleteChildElements a. Receives a parentElement as a parameter b. Define a child variable as parentElement.lastElementChild c. While the child exists...(use a while loop) d. Use parentElement.removeChild to remove the child in the loop e. Reassign child to parentElement.lastElementChild in the loop f. Return the parentElement NOTE: The above functions had no dependency on other functions. They were very self-contained which is ideal. That is not always possible though. We will try to limit dependencies as we go. The next several functions have small dependencies. 6. addButtonListeners a. Selects all buttons nested inside the main element b. If buttons exist: c. Loop through the NodeList of buttons d. Gets the postld from button.dataset.postld e. Adds a click event listener to each button (reference addEventListener) f. The listener calls an anonymous function (see cheatsheet) g. Inside the anonymous function: the function toggleComments is called with the event and postid as parameters h. Return the button elements which were selected i. You may want to define an empty toggleComments function for now. Not all tests will pass for addButtonListeners until toggleComments exists. I recommend waiting on the logic inside the toggleComments function until we get there. 7. removeButtonListeners a. Selects all buttons nested inside the main element b. Loops through the NodeList of buttons c. Gets the postld from button.dataset.id d. Removes the click event listener from each button (reference removeEventListener) e. Refer to the addButtonListeners function as this should be nearly identical f. Return the button elements which were selected 8. createComments a. Depends on the createElemWith Text function we created b. Receives JSON comments data as a parameter c. Creates a fragment element with document.createDocumentFragment() d. Loop through the comments e. For each comment do the following: f. Create an article element with document.createElement() g. Create an h3 element with createElemWith Text('h3', comment.name) h. Create an paragraph element with createElemWith Text("p', comment.body) i. Create an paragraph element with createElemWith Text("p', 'From: S{comment.email}') j. Append the h3 and paragraphs to the article element (see cheatsheet) k. Append the article element to the fragment I. Return the fragment element
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY