const btns = document.querySelectorAll('.damage');
const elem = document.querySelector('.char');
const char = {
good: '#2CCE62',
ok: '#BCCE5C',
bad: '#CE6C1D',
crit: '#D8272E',
health: 200
}
btns.forEach(btn => btn.addEventListener('click', onDamage));
function onDamage({target}) {
if (target.value === 'Лечение' && char.health > 0 && char.health < 200) {
char.health += 5;
} else if (target.value === 'Урон' && char.health > 0 && char.health <= 200) {
char.health -= 5;
} else if (target.value === 'Крит. урон' && char.health > 0 && char.health <= 200) {
char.health -= 50;
}
if (char.health >= 200) char.health = 200;
if (char.health <= 0) char.health = 0;
if (char.health >= 150) elem.style.background = char.good;
else if (char.health >= 100) elem.style.background = char.ok;
else if (char.health >= 50) elem.style.background = char.bad;
else if (char.health > 0) elem.style.background = char.crit;
else btns.forEach(e => e.value = 'Смерть!');
elem.style.height = `${char.health}px`;
}