dimanche 26 février 2023

Just started learning javasript from "Bro code" and he was creating random number generator, and i did the same thing he did but my code's not working [closed]

So when went to console there is an error(Uncaught TypeError: Cannot set properties of null (setting 'onclick'). So i check if I wrote all ID names correctly but no there is no mistake.

After pressing the button "submit" three random numbers have to appear but it doesn't happen.

Here's the code:


let x;
let y;
let z;

document.getElementById("rollButton").onclick = function(){    
 
    x = Math.floor(Math.random() * 7);
    y = Math.floor(Math.random() * 7);
    z = Math.floor(Math.random() * 7);

    document.getElementById("xlabel").innerHTML = x;
    document.getElementById("ylabel").innerHTML = y;
    document.getElementById("zlabel").innerHTML = z;
}
HTML:
    <label class="xlabel"></label><br>
    <label class="ylabel"></label><br>
    <label class="zlabel"></label><br>
    <button class="rollButton">roll</button>




Aucun commentaire:

Enregistrer un commentaire