# Alternative Solution to this problem?

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

1. Why must we generate from 1 to 5 for variable damageThisRound, we just need 1,2,3,4 since there are only 4 hits. instead of if (totalDamage >=4), this could be if (totalDamage =4)
2. Why must we add another variable â€śtotalDamageâ€ť? we only need â€śdamageThisRoundâ€ť as seen from my code since totalDamage is set to 0?

```

var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*4+1);

while(slaying) {
if (youHit) { console.log (â€śYout hit the dragonâ€ť);
if (damageThisRound = 4) {
console.log(â€śYou slew the dragonâ€ť);
slaying =false;}
else {youHit = Math.floor(Math.random()*2);
}

``````} else {console.log("The dragon defeated you");
``````

slaying = false;
}
}

``<do not remove the three backticks above>``

#2

Now, there is only a small change the random number is 4, while if it can be 4 and 5, you have a better change of beating the dragon. this:

``````if (totalDamage =4)
``````

is a particular bad idea, now you always win (you assign a value of 4 to totalDamage, positive integers are considered true), you might want to use two equal signs instead (or even better, use `>=`)

I am slightly confused, but i think this game build in totalDamage, to offer you an opportunity, to expand the game (but is not part of the tutorial). if you could hit multiply times, you most certainly want to have `>= 4`, since 3 + 2 = 5, which is greater then 4, if you use `==`, then `5 == 4` is false, so you loose, while you killed the dragon

#3

As far as Iâ€™ve understand it, totalDamage is kind of like the dragons HP, so you do damage each round and once the damage exceed a threshold youâ€™re done. Iâ€™ve no idea why this is done by accumulating damage instead of decreasing a dragonHP variable but I guess that was the idea.

#4

guess so, but you can also just do one hit, so it seems a bit pointless

#5

Yes if you draw a 4 or even 5 for damageThisRound it is a one hit, if youâ€™re lucky with the youHit as well, but for a 1 it could get pretty hard for your luck to be effective

#9