3
Good morning/evening guys, I’m having a really boring problem, I’m creating a website for a school biology project, about cells. On this site I have to make a loop that performs an action, wait X seconds and perform another action, wait more Y seconds and return to the beginning of the loop. I found some code using async functions but when I try to apply them the browser runs once and returns me an error Uncaught Syntaxerror: Unexpected Identifier line number 1 of html (every 2s it throws me dnv error). JS:
function first(){
setTimeout(() => {
console.log('first')
}, 1000);
}
function second(){
setTimeout(() => {
console.log('second')
}, 1000);
}
let run = async ()=>{
await first();
await second();
}
setInterval(run(), 1000);
When I comment on that part, the error goes away. I don’t know much about async and await, but I’ve tried everything to do that and so far this is the most promising method. I hope you understand what I mean, thank you very much and possibly good night.