You’re not passing the timeout a function. It needs to say:
setTimeout(
() => alert("Totaler Absturz. Score: " + Math.floor(counter / 100)),
5000
);
It’s the () => ...
bit that will wrap your alert in a function. If it’s not wrapped in a function, it will execute immediately.
Gruß
I need a sound to play while or before a score alert pops up (simple dinosaur game). Right now it just shows the alert and then it plays the sound. I have tried to set a timeout but it doesn’t work.
if (blockLeft < 200 && blockLeft > 0 && characterTop >= 300) {
const death = new Audio((URL = "/sound/death.mp3"));
death.play();
death.volume = 0.4;
block.style.animation = "none";
block.style.display = "none";
setTimeout(
alert("Totaler Absturz. Score: " + Math.floor(counter / 100)),
5000
);
counter = 0;
}
I put in the function that plays the sound (exactly how you suggested) and it still sends the alert before the sound plays. Gruß
the audio file has a size of 50KB and it plays immediatly after I click ok on the alert
hey man I managed to get it to work. turned out github took a bit to load everything.. Im still trying to figure out how everything works yk. have nice day