Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,193,281 members, 7,950,463 topics. Date: Monday, 16 September 2024 at 02:38 PM

Javascript Help - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Javascript Help (635 Views)

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)

(1) (Reply) (Go Down)

Javascript Help by cammyjr(m): 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

1 Like

Re: Javascript Help by cammyjr(m): 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

1 Like

Re: Javascript Help by cammyjr(m): 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

1 Like

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)

Where Can I Learn Programming At A Relatively Cheap Price / Computer Hardware/software Repair / Fixed Sidebar Menu HTML CSS - How To

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.