Anonymous
Как мне уменьшить оставшееся здесь здоровье до нуля?
Сообщение
Anonymous » 02 мар 2026, 20:52
Мне не удалось решить эту проблему.
Код: Выделить всё
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
1772473959
Anonymous
Мне не удалось решить эту проблему. [code]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}`) } })[/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79898820/how-do-i-reduce-the-remaining-health-here-to-zero[/url]