# Deleted

#1

``````var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;

while(slaying)
{
console.log(youHit);
if(youHit==1)
{
console.log("Congo! You Hit The Dragon Bruhh !!");
totalDamage+= damageThisRound;
var inc = true;
while(inc)
{
if(totalDamage>=4)
{
console.log("You slew that Dragon piece of shit ! Wuuu huuuu!! ");
inc=false;
slaying = false;
}
else
{
youHit=(Math.floor(Math.random()*2));
}
}
}
else
{
console.log("You Missed Son ! You a loser !! Cant believe I wasted my time on you..");
}
slaying=false;
}``````

#2

why did you add another while loop?

only if the damage is greater or equal then 4, inc is set to false, if this is not the case (totalDamage is 3 or less), the program is stuck in the `while(inc)` loop

I don't see why you should add another loop, it is most certainly not part of the exercise

#3

I'm trying to get 'youHIt' every time the dragon gets hit till he is slain and not just in one go the dragon is hit and slain.

#4

but your `while(slaying)` loop is doing this for you?

you have a 50% change to hit, if you hit, you do damage, which is added to the total damage. if the damage is enough, you killed the dragon.

if the damage is not enough, youHit is calculated again, another 50% change to hit, if you hit, more damage is done, either until the dragon is dead, or you miss.

#5

Please Ignore the statements i didnt realise i left them in there !

#6

ohhhh ok thank you i didnt realise that

#7

My eyesight was just stuck at if(youHit==1)

#8

i would personally move this line:

``var damageThisRound = Math.floor(Math.random()*5 + 1);``

to here:

``````if(youHit==1)
{
var damageThisRound = Math.floor(Math.random()*5 + 1);``````

this way, new damage gets calculated every round.

take a good look how the program works, add more `console.log()` to see what the program is doing if need be, and run the program multiply times

#9

Yup! Thank you! its always the stupidest things that get me !

#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.