javascript - no color change after 10 seconds -


i have fiddle in after every second changing background color different color.

i wondering changes need make in javascript code below present in fiddle there no color change after 10 seconds. js code using is:

var = 0;    function change() {    var doc = document.getelementbyid("background");    var color = ["black", "blue", "brown", "green", "red", "yellow", "white", "pink", "purple", "orange"];    doc.style.backgroundcolor = color[i];    = (i + 1) % color.length;  }  myvar = setinterval(change, 1000);
html,  body {    border: 0;    margin: 0;    height: 100%;    min-height: 100%;  }    .container {    width: 100% !important;  }    #background {    width: 100%;    height: 100%;  }
<div id="background">  </div>

clear interval after 10 seconds timeout

try this:

var = 0;    function change() {    var doc = document.getelementbyid("background");    var color = ["black", "blue", "brown", "green", "red", "yellow", "white", "pink", "purple", "orange"];    doc.style.backgroundcolor = color[i];    = (i + 1) % color.length;  }  myvar = setinterval(change, 1000);  settimeout(() => {    clearinterval(myvar);  }, 10000);
html,  body {    border: 0;    margin: 0;    height: 100%;    min-height: 100%;  }    .container {    width: 100% !important;  }    #background {    width: 100%;    height: 100%;  }
<div id="background">  </div>


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -