async function userTurn() {
  let userPlaying = true;
  if (userInput.length === sequence.length) { // let user advance without waiting
    if (JSON.stringify(userInput) === JSON.stringify(sequence)) {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      $('h1').addClass('level-up');
      level++;
      setTimeout(function() {$('h1').removeClass('level-up');}, 200);
      userTime -= 50; // decreases time available
      userPlaying = false;
      playGame();
    }
  }

  if (userPlaying) {
    await delay(userTime * sequence.length);

    if (JSON.stringify(userInput) === JSON.stringify(sequence)) {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      $('h1').addClass('level-up');
      level++;
      setTimeout(function() {$('h1').removeClass('level-up');}, 200);
      userTime -= 50; // decreases time available
      playGame();
    } else {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      let wrongSound = new Audio('sounds/wrong.mp3');
      wrongSound.play();
      $('body').addClass('game-over');
      setTimeout(function() {$('body').removeClass('game-over');}, 180);
      setTimeout(failure, 220);
    }
  }
}
//I think I can solve the above with recursion without using the async/Promise/await. At the end of the function in the setTimeout func stmnt, I should call the function again (recurse), this should make it wait. let i = 0 before func, i++ at end, call func again, and at top if i === sequence.length - 1, then console.log('Sequence finished, now it's your turn!), else the func continues to call!
I think I can solve the above with recursion without using the async/Promise/await. At the end of the function in the setTimeout func stmnt, I should call the function again (recurse), this should make it wait. let i = 0 before func, i++ at end, call func again, and at top if i === sequence.length - 1, then console.log('Sequence finished, now it's your turn!), else the func continues to call!
I think I can solve the above with recursion without using the async / Promise / await . At the end of the function in the setTimeout func stmnt I should call the function again ( recurse ) this should make it wait . let i = 0 before func i ++ at end call func again and at top if i === sequence . length - 1 then console . log ( ' Sequence finished now it ' s your turn! ) else the func continues to call!
async function userTurn() {
  let userPlaying = true;
  if (userInput.length === sequence.length) { 
    if (JSON.stringify(userInput) === JSON.stringify(sequence)) {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      $('h1').addClass('level-up');
      level++;
      setTimeout(function() {$('h1').removeClass('level-up');}, 200);
      userTime -= 50; 
      userPlaying = false;
      playGame();
    }
  }
  if (userPlaying) {
    await delay(userTime * sequence.length);
    if (JSON.stringify(userInput) === JSON.stringify(sequence)) {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      $('h1').addClass('level-up');
      level++;
      setTimeout(function() {$('h1').removeClass('level-up');}, 200);
      userTime -= 50; 
      playGame();
    } else {
      console.log('current sequence:', sequence);
      console.log('current userInput:', userInput);
      let wrongSound = new Audio('sounds/wrong.mp3');
      wrongSound.play();
      $('body').addClass('game-over');
      setTimeout(function() {$('body').removeClass('game-over');}, 180);
      setTimeout(failure, 220);
    }
  }
}
async function userTurn ( ) { let userPlaying = true ; if ( userInput . length === sequence . length ) { if ( JSON . stringify ( userInput ) === JSON . stringify ( sequence ) ) { console . log ( 'current sequence:' , sequence ) ; console . log ( 'current userInput:' , userInput ) ; $ ( 'h1' ) . addClass ( 'level-up' ) ; level ++ ; setTimeout ( function ( ) { $ ( 'h1' ) . removeClass ( 'level-up' ) ; } , 200 ) ; userTime -= 50 ; userPlaying = false ; playGame ( ) ; } } if ( userPlaying ) { await delay ( userTime * sequence . length ) ; if ( JSON . stringify ( userInput ) === JSON . stringify ( sequence ) ) { console . log ( 'current sequence:' , sequence ) ; console . log ( 'current userInput:' , userInput ) ; $ ( 'h1' ) . addClass ( 'level-up' ) ; level ++ ; setTimeout ( function ( ) { $ ( 'h1' ) . removeClass ( 'level-up' ) ; } , 200 ) ; userTime -= 50 ; playGame ( ) ; } else { console . log ( 'current sequence:' , sequence ) ; console . log ( 'current userInput:' , userInput ) ; let wrongSound = new Audio ( 'sounds/wrong.mp3' ) ; wrongSound . play ( ) ; $ ( 'body' ) . addClass ( 'game-over' ) ; setTimeout ( function ( ) { $ ( 'body' ) . removeClass ( 'game-over' ) ; } , 180 ) ; setTimeout ( failure , 220 ) ; } } }
I think I can solve the above with recursion without using the async/Promise/await.
I think I can solve the above with recursion without using the async / Promise / await .
// let user advance without waiting // decreases time available // decreases time available