let variants = [
{ condition: (tries === 0), alert: 'У вас закончились попытки' },
{ condition: (value == number), alert: 'Поздравляю, вы угадали', returnValue: true },
{ decreaseTries: true }
];
for(let i = 0; i < variants.length; ++i) {
let v = variants[i];
if(typeof v.condition === 'undefined' || v.condition) {
if(v.alert) {
alert(v.alert);
}
if(v.decreaseTries) {
tries--;
triesSpan.textContent = declOfNum(tries, ['попытка', 'попытки', 'попыток']);
triesTitle.textContent = `У вас осталось ${tries} ${triesSpan.textContent}`;
}
return v.returnValue || false;
}
}
Все варианты перечислять не стал, нужные добавляются по аналогии.