+ 1

Please someone help me with this JS code

So I was making a random number generator and I got stuck when the code is not working properly whenever I click on the button that doesn't erase the old output instead it's keep going on the old output so I need help in this code like whenever I click on the button the old output should be erased and new output will be written Please help I wish for you that you can never forget codes like I došŸ™ https://code.sololearn.com/W6M8byt35b1E/?ref=app

15th Oct 2022, 2:17 PM
Umair Ansari
Umair Ansari - avatar
6 Answers
15th Oct 2022, 2:45 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
don't append text to the body, you should be targeting a tag that hold your text. it's possible by using an Id. <p id="result"></p> let resultElement = document.getElementById("result"); resultElement.innerText = number; I hope this help :)
15th Oct 2022, 2:24 PM
Apollo-Roboto
Apollo-Roboto - avatar
0
Can you please make a code please šŸ™
15th Oct 2022, 2:34 PM
Umair Ansari
Umair Ansari - avatar
0
Just create a new text tag give it a id and simply replace body in you js by getElementById("Id")
17th Oct 2022, 11:19 AM
Sujas Kumar
Sujas Kumar - avatar
0
And you are good to go
17th Oct 2022, 11:19 AM
Sujas Kumar
Sujas Kumar - avatar
0
Also remove that += and simply use =
17th Oct 2022, 11:20 AM
Sujas Kumar
Sujas Kumar - avatar