₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,646 members, 8,427,423 topics. Date: Monday, 15 June 2026 at 09:58 PM

Toggle theme

Javascript Help - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingJavascript Help (689 Views)

1 Reply (Go Down)

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\ !!!"wink
totalDamage += damageThisRound;
if (totalDamage >= 4) {
console.log("You slew the\ dragon"wink;
slaying = false;
}
else {
youHit = Math.floor(Math.random() * 2);
}
else {
console.log("You Lose"wink;
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:
Please provide the codecademy page. . . .your code snippet is lacking the condition required in the while loop
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:
I don't think so. It's testing for a boolean which returns true.
OP, any error messages?
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.
1 Reply

Great Videos To Learn Css, Php, Msql And Javascript [HELP]Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysqlWere Can I Download Free Video Tutorials On Javascript Or Ruby234

How To Apply Adclx To BlogThe Cheapest Way Of Shipping Goods From The UK & USA To NigeriaI Need CAC Registration Urgently