11. Infinity Loop


#1

I'm sure I'm messing this somewhere in here, but I'm not sure where. This is crashing. Is the while/do loops messed up?

Thanks for looking!
var dragon = true;
var dragon = function (){
while (dragon)
{
console.log("die!");
dragon=false;
for (var health = 100; health<1; health--)
{
console.log("killing!");

}
while(dragon <1)
health--;
}
do{
console.log("not sure");
} while (dragon);

};
dragon();


#2

First of all please use more variable then just dragon because your dragon = true; gets directly overwritten by the dragon function and a function as condition doesn't make much sense.


#3

We cannot use the same variable name for both the control and the function.

var flag = true;
var dragon = function () {
    while (flag) {
        flag = false;
    }
};
dragon();

This should get you started toward a solution.


#4

I either type too slow, or try to say too much. Keep getting my toes stepped on. Wish there was some way to check out a question so we're not trampling over each other.


#5

:smile: yeah for the second time. Guess the problem is that we instant reply on a watched topic and the time distance was therefore to short to see the answer. But I'm off soon anyway. Good night!


#6

Please don't take this as an objection, as much as an apology. Nobody wants you to go (unless you have a warm pillow awaiting).


#7

No, everything cool, a warm pillow is awaiting me just checking the recent messages :smile:


#8

Okay, cool. Have a good night!


#9

I had my function as dragonFight. Why I changed it, no idea.


#10

changed the function name and now it all works. Thanks guys!