This is my snippet of code for the setInterval:
var t = 0;
var speed = 1000;
// To display the speed
setInterval(displaySpeed, 100);
setInterval(timer, speed);
// To diplay the speed as well
function displaySpeed(){
document.getElementById("Tem").textContent = speed;
}
function speedUp(){
speed = speed - 100;
}
function slowDown(){
speed = speed + 100;
}
function timer(){
t = Math.floor(Math.random() * 16) + 1;
changeBackground();
}
The speedUp() and slowDown() are connected to a button with onclick. The buttons will change the variable, but not the actual speed. The timer function is to select a random number between 1 and 16.