I am doing the Simon Game (last project of frontend). I’ve needed a function that waits for user answer. So, I made this function:
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
And I used it on my start function (the Simon Game engine):
async function start() {
var audio;
isRunning = true;
addSound(); // add new audio to sequence
while(ON) {
playSequence(0, audio);
// wait 7s for user answer
await sleep(7000);
if(isAnswerCorrect()) {
count++;
addSound();
} else {
count = 0;
// answer incorrect: play corresponding audio
var audio = playAudio(5);
setTimeout(stopAudio(audio), 1000);
}
aux = 0;
$("#spaceCount").html(count);
}
}
But this function is causing the following error: Unexpected token function.
What does that mean?
My code is here: http://codepen.io/raulfm/pen/qmdwpb?editors=1010