More on the practice website

I had a good idea for my practice website. I would like to press a button which would generate a random number using math.random. Then, depending on the result( I think i would use if/else statements) I would like it to change the background color. something like if(number) < .33 make background red, else if(number) < .66, make background blue, else make background yellow. How would I go about this? Thanks!!

Pick a random number, then use an if/else if/else statement to choose the color to change it to.
Do another Google search.


    <button id="button" onclick="funcToRun();">Sample Website</button>
function funcToRun() {
    var randomNumber = Math.random();
    if (randomNumber <= 0.33) { = 'red';
    else if (number <= 0.66) { = 'blue';
    else { = 'yellow';


Again… simple VanillaJs, you should already know this if you finished the Js course…

1 Like

Ok, this is what I was thinking. Thanks for taking the time to help me. I going to try it now.

1 Like

Btw @ithortureu this is not jQuery, this is pure JS (Vanilla JS)