Я не смог понять, как решить эту проблему.
const healths = [{ 1: 100 }, { 2: 100 }, { 3: 100 }, { 4: 100 }, { 5: 100 }, { 6: 100 }];
healths.forEach((curr, i) => {
// console.log(`${curr[i + 1]}`)
const damage = Math.trunc(Math.random() * (12 - 4 + 1)) + 4;
let remainingHealth = curr[i + 1] - damage;
if (i < healths.length - 1) {
console.log(`${i + 1}. player made a move, ${i + 2} knight's remaining health is ${remainingHealth}`)
}
else if (i === healths.length - 1) {
console.log(`${i + 1}. player made a move, ${i - (healths.length - 2)} knight's remaining health is ${remainingHealth}`)
}
})
Подробнее здесь: https://stackoverflow.com/questions/798 ... re-to-zero