How to write to the computer to remove the elements "p" if they are more than one on the page?

  • 0
    let button = document.getElementById("btn1")
    
           function clickMe() {
               alert("Сейчас будем играть игру - Угадай число");
               let p = document.createElement("p");
                p.innerHTML = "Угадай число от 0 -> 100";
                document.body.appendChild(p);
    
                if (document.getElementsByTagName("p").length > 1) {
                    document.getElementsByTagName("p").removeChild;
                }
                setTimeout((function () {
                    let creatingRandomNum = Math.random();
                    creatingRandomNum = (creatingRandomNum * 100) + 1;
                    creatingRandomNum = Math.floor(creatingRandomNum);
                    for (;;) {
                        let askRandomNum = prompt("Напишите число которые вы угадали");
                        if (Number(askRandomNum) === creatingRandomNum) {
                            alert("Вы угадали!");
                            break;
                        }
                        if (Number(askRandomNum) > creatingRandomNum && Number(askRandomNum) != null && Number(askRandomNum) != undefined) {
                            alert("Вы написали выше указзанного числа");
                        }
                        if (Number(askRandomNum) < creatingRandomNum && Number(askRandomNum) != null && Number(askRandomNum) != undefined) {
                            alert("Вы написали меньше указзанного числа");
                        }
                        if (askRandomNum == null) {
                            alert("Загаданное число это - " + creatingRandomNum);
                            break;
                        }
                    }
                }), 2000);
           }


    each time you press, a message is generated - "Guess the number from 0 - & gt; 100" ". It is necessary to write a code so that the computer will delete such a message if they are more than one (Repeated pressing did not create a new same message). I tried using this code [[ [0_1]]]

    don’t lend, I’m still a beginner. thanks
    JavaScript Scarlett Hahn, Nov 5, 2020

  • 1 Answers
  • 0
    1. You are not using removeChild correctly

    2. Use either setInterval or MutationObserver to track the page
    Ethan Dennis

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!