Мне нужно чтобы здоровье у Гриффина отнималось до тех пор пока не станет равное нулю
const Witcher = {
Whealthpoint: 1000,
Wdefencepoint: 100,
Wstrength: 120,
Wweapon: 250,
};
const Griffin = {
Ghealthpoint: 2000,
Gdefencepoint: 120,
Gstrength: 150,
Gweapon: 0,
};
let damage = 250;
let probability = Math.random();
for (let i = 0; i = Ghealthpoint; i--){
function hit(Griffin){
if (probability > 0.7){
alert('вы нанесли гриффону' + ' ' + '250' + ' ' + 'урона' + ',' + ' ' + 'у Гриффона соталось' + ' ' + '1750' + ' ' + 'HP');
}
else{
alert('не попал')
}
}
}
Ответы (1 шт):
Автор решения: ThisMan
→ Ссылка
У вас немного бардак в коде, чуть чуть подправил

const Witcher = {
Whealthpoint: 1000,
Wdefencepoint: 100,
Wstrength: 120,
Wweapon: 250,
};
const Griffon = {
Ghealthpoint: 2000,
Gdefencepoint: 120,
Gstrength: 150,
Gweapon: 0,
};
let damage = 250;
function hit(griffon, chance) {
if (chance > 0.7) {
griffon.Ghealthpoint -= damage;
alert(`Вы нанесли грифону ${damage} урона, у грифона осталось ${griffon.Ghealthpoint} HP`);
} else{
alert('Промах')
}
}
while(Griffon.Ghealthpoint > 0) {
let probability = Math.random();
hit(Griffon, probability)
}
alert('Грифон убит');