001function createNodeWithText(newNodeType, newNodeText)
002{
003 const newNode = document.createElement(newNodeType);
004 const newText = document.createTextNode(newNodeText);
005 newNode.appendChild(newText);
006 return newNode;
007}
008
009
010function replaceNode(replacementNode, elemParent, textToBeReplaced ) {
011
012 for (let i = 0; i < elemParent.children.length; i++) {
013 if (elemParent.children[i].innerText === textToBeReplaced) {
014 elemParent.replaceChild(replacementNode, elemParent.children[i]);
015 }
016 }
017}
018
019window.onload = function()
020{
021 const ulElement = document.getElementById('pokemon');
022 const replacementNode = createNodeWithText("LI", "Squirtle");
023 replaceNode(replacementNode, ulElement, "Mr Messy");
024
025 const newParagraphNode = createNodeWithText("P", "What is your favorite pokemon?");
026
027 ulElement.insertAdjacentElement('afterend', newParagraphNode);
028
029
030
031}