Why its not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why its not working?

Error: "Uncaught TypeError: Cannot set properties of null (setting 'Onclick') Line: 9" https://code.sololearn.com/W89xGjUuCfhm/?ref=app

27th Mar 2022, 3:34 AM
lavie
lavie - avatar
2 Answers
+ 2
You will know why after you read this https://www.sololearn.com/post/90825/?ref=app This way it shows different values on each click because <x>, <y> and <z> are generated as the button was clicked. window.onload = function() { document.getElementById("btn") .onclick = function() { let x= Math.floor((Math.random()*6)+1); let y= Math.floor((Math.random()*6)+1); let z= Math.floor((Math.random()*6)+1); document.getElementById("xlabel") .innerHTML = x; document.getElementById("ylabel") .innerHTML = y; document.getElementById("zlabel") .innerHTML = z; } }
27th Mar 2022, 4:06 AM
Ipang
0
Thanks
27th Mar 2022, 10:07 AM
lavie
lavie - avatar