let promise = new Promise(function(resolve, reject){
let intervalId = setInterval(winner = function(){
setTimeout(function () {
damage = getDamage(firstFighter, secondFighter);
if (damage > 0) {
console.log(secondFighterHealth + "-" + damage);
secondFighterHealth -= damage;
} else {
console.log('Второй блокировал удар первого!');
}
if (secondFighterHealth <= 0) {
winner = firstFighter;
clearInterval(intervalId);
resolve(firstFighter);
}
console.log('Second Health: ' + secondFighterHealth);
console.log('PAUSE!');
}, 250);
setTimeout(function(){
damage = getDamage(secondFighter, firstFighter);
if (damage > 0) {
console.log(firstFighterHealth + "-" + damage);
firstFighterHealth -= damage;
} else {
console.log('Первый блокировал удар второго!');
}
if (firstFighterHealth <= 0) {
winner = secondFighter;
clearInterval(intervalId);
resolve(winner);
}
console.log('First Health: ' + firstFighterHealth);
console.log('PAUSE!');
}, 500);
}, 750);
});
promise.then(function(winner){
return winner;
});