I just started studying Javascript and I'm trying to create a mini-game. I want to get the vocation of a character comparing if his health skill and attack skill are bigger than magic and speed, then he's a knight. But what I'm trying is not working.
if (hp1 && at1 > mg1 && sp1){
document.querySelector('.badgesContainer .knight').style.display = 'block'
}
else{
document.querySelector('.badgesContainer .druid').style.display = 'none'
document.querySelector('.badgesContainer .knight').style.display = 'none'
document.querySelector('.badgesContainer .paladin').style.display = 'none'
document.querySelector('.badgesContainer .sorcerer').style.display = 'none'
}
hp1 && at1 > mg1 && sp1actually means just: if hp is truthy and at1 is bigger than mg1 and sp1 is truthy.hp1 > mg1 && hp1 > sp1 && at1 > mg1 && at1 > sp1.vocationproperty. It makes things easier down the road.if ((hp1 + at1) > (mg1 + sp1)), which simply adds hp and attack, then checks if that's greater than the total for magic and speed.