web - javascript: program get stuck -


i'm learing javascript on codecademy. following program got stuck when submitted it. new can not find bug. downloaded aptana studio don't know how debug:(. there way trace code? in advance.

var slaying = true; var youhit = math.random() > 0.5; var damagethisround = math.floor(5 * math.random()); var totaldamage = 0;  while (slaying) {     if (youhit) {         console.log("you hit dragon.");         totaldamage += damagethisround;         if (totaldamage >= 4) {             console.log("you've stew dragon!");             slaying = false;         } else {             youhit = math.random() > 0.5;         }     } else {         console.log("the dragon defeated you.")     } } 

as per understanding. need set slaying = false in else section, otherwise program thrown infinite loop.

} else {     slaying = false; //added here - breaks while() condition     console.log("the dragon defeated you.") } 

simple, when the dragon defeated you. slaying stops. (pun intended)

for debugging use chrome's built in developer tools or firebug in firefox. both, use f12 access whilst in chosen browser.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -