Javascript Help - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Javascript Help (689 Views)
| Javascript Help by cammyjr(op): 10:01am On Jul 04, 2015 |
Good morning , please I need help on this particular page on codecademy's tutorial, I seem to be stuck and its taking forever to find out what's wrong with this code. Its for a dragon slayer game. Kindly assist. var slaying = true; youHit = Math.floor(Math.random() * 2) damageThisRound = Math.floor(Math.random() * 5 + 1) totalDamage = 0 while (slaying) { if (youHit) { console.log("You Hit the Dragon\ !!!" ![]() totalDamage += damageThisRound; if (totalDamage >= 4) { console.log("You slew the\ dragon" ;slaying = false; } else { youHit = Math.floor(Math.random() * 2); } else { console.log("You Lose" ;slaying = false; } } |
| Re: Javascript Help by olaboy33(m): 10:04am On Jul 04, 2015 |
Fgdhjsklatyuioewpbnc,x.z |
| Re: Javascript Help by cammyjr(op): 10:21am On Jul 04, 2015 |
?? |
| Re: Javascript Help by Nobody: 10:47am On Jul 04, 2015 |
Please provide the codecademy page. . . .your code snippet is lacking the condition required in the while loop |
| Re: Javascript Help by cammyjr(op): 11:17am On Jul 04, 2015 |
| Re: Javascript Help by Nobody: 12:07pm On Jul 04, 2015 |
I did not see any error there: The next excercise that gives you a blank screen gives you 4 instructions: all you need to enter is var slaying = true; var youHit = Math.floor(Math.random() * 2); var damageThisRound = Math.floor(Math.random() * 5 + 1); var totalDamage = 0; To move on to the next stage where you learn the while loop. |
| Re: Javascript Help by Craigston: 12:12pm On Jul 04, 2015 |
donjayzi:I don't think so. It's testing for a boolean which returns true. OP, any error messages? |
| Re: Javascript Help by Nobody: 12:15pm On Jul 04, 2015 |
Craigston:same here var slaying = true; (while slaying) ; infinite loop |
| Re: Javascript Help by Olumyco(m): 12:30pm On Jul 04, 2015 |
The problem wit d code is traceable to the while loop. |
Great Videos To Learn Css, Php, Msql And Javascript [HELP] • Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql • Were Can I Download Free Video Tutorials On Javascript Or Ruby • 2 • 3 • 4
How To Apply Adclx To Blog • The Cheapest Way Of Shipping Goods From The UK & USA To Nigeria • I Need CAC Registration Urgently
