I have this code where it runs through all the categories sends a post (console log) and once it reaches the end it will restart. I am trying to find a way for each subsequent category to be delayed by a certain amount of time. (for testing purposes 1 second, but ultimately 1 hour) I tried to use a function as well as taking the function contents out and do it separately.
// I put this above const CategoryTimer
let defaultTime = 1000;
let time = defaultTime + (curPost * 1000);
// And then I put time in place of CategoryTime(curPost) below.
I'm pretty confused as to what to do but once I figure this part out I can finally get this project back on track. Thank you all in advance!
// Command
let curPost = 0;
const CategoryTimer = setInterval(() => {
// Database Call
let categories = ["sad", "toebeans", "meows", "tucked", "smol", "chonky"];
// Make post
console.log(`Post for ${categories[curPost]}`);
if (curPost === categories.length - 1) {
curPost = -1;
console.log("Restart!");
}
curPost++;
}, CategoryTime(curPost));
function CategoryTime(curPost) {
let defaultTime = 100000;
return defaultTime + (curPost * 1000);
}