Javascript


#1


I have made a code that auto changes color. How do I make it show on screen how many times it has changed. Code below

function funcToRun() {
  window.setTimeout( "funcToRun()", 100);
    var randomNumber = Math.random();
    if (randomNumber <= 0.10) {
        document.body.style.background = 'red';
    }
    else if (randomNumber <= 0.20) {
        document.body.style.background = 'blue';
    }
    else if (randomNumber <= 0.30) {
        document.body.style.background = 'lime';
    }
    else if (randomNumber <= 0.40) {
        document.body.style.background = 'fuchsia';
    }
    else if (randomNumber <= 0.50) {
        document.body.style.background = 'pink';
    }
    else if (randomNumber <= 0.60) {
        document.body.style.background = 'magenta';
    }
    else if (randomNumber <= 0.70) {
        document.body.style.background = 'orange';
    }
    else if (randomNumber <= 0.80) {
        document.body.style.background = 'aqua';
    }
    else if (randomNumber <= 0.90) {
        document.body.style.background = 'violet';
    }
    else {
        document.body.style.background = 'yellow';
    }
}


#2

2 posts were merged into an existing topic: Javascript


#3