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...


Need help with these Javascript functions please!


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

Extracted 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: ${comment.email}') j. Append the h3 and paragraphs to the article element (see cheatsheet) k. Append the article element to the fragment Return the fragment element I.
Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here