I need to create a delay in js. I could use setTimeout but then the code continues to execute. During the delay, I want the script to do nothing. Is there any way to do this?? To be more clear: Eg. If I am doing two animations.
1)first animation. 2)delay(nothing is done for a second) 3)second animation.
EDIT:
First Animation:
function animateScreen() {
var audio = new Audio("http://www.sounds.beachware.com/2illionzayp3may/illwavul/CLNKBEEP.mp3");
$("body").toggleClass("wrongSeries");
audio.play();
}
function wrongChoice() {
animateScreen();
setTimeout(animateScreen, 100);
}
2) delay
3) Second Animation:
animateYellow(true);
setTimeout(function() {
animateYellow(false);
}, 500);
function animateYellow(lightup) {
if (lightup) {
var audio = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
audio.play();
}
$("#4").toggleClass("animateYellow");
}
This is the code I am currently using. The second animation exists for four different colors.