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>

9th Dec 2019, 10:55 PM
Ahmed Belkhodja
2 Antworten
+ 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
10th Dec 2019, 4:35 AM
Gordon
Gordon - avatar
0
becouse click twice, not just once
13th Dec 2019, 1:19 PM
Ahmed Belkhodja