0
DOM & Events Creating an Image Slider
The code is in the address above Is there no error in this code? The result is assumed 10, not 5 What will be the content of the paragraph after the user clicks on it twice? <p id='txt' onclick='test();'>20</p> <script> function test() { var x=document.getElementById('txt'); var n = x.innerHTML; x.innerHTML = n/2; } </script>
2 odpowiedzi
+ 1
innerHTML returns a string.
Trying to apply division in string results in NaN (Not a number).
The correct way is to use Number.parseInt(n) for division instead.
https://www.sololearn.com/post/115377/?ref=app
https://www.sololearn.com/post/115762/?ref=app
https://code.sololearn.com/WKKkpq0efxai/?ref=app
0
becouse click twice, not just once