My goal is to create a continuous loop through an array of number values. These values will be used as delay parameters in a setInterval function, triggering another function each time. Here's what I've come up with:
HTML:
<p>On</p>
JavaScript:
$(document).ready(function(){
var timings = [5000, 10000, 17000, 8000, 14000, 9000, 12000, 8000, 20000, 7000, 13000, 7000, 17000, 8000, 13000, 12000, 18000]
//function to modify
function modify(){
var p = $("p").html();
if(p === "On"){
$("p").html("Off");
} else {
$("p").html("On");
}
}
function myNewFunction(){
for (var i = 0; i < timings.length; i++){
var switchTime = timings[i];
setInterval(function(){
modify();
},switchTime);
}
} myNewFunction();
});
I aim to have the modify function execute continuously at varying intervals. However, when I run this code, the timing doesn't seem to be functioning correctly. Any insights or suggestions would be greatly welcomed. Thank you!