Sunday, 15 July 2012

javascript - Broken If/Else Statement using Randomizer -


OK, I'm still starting JavaScript, but I try to type a rock-paper-scissy type game I am doing Everything is working very well, except that every time I run the "reload" function the output is that first "if" second if / Else statement This means that the output "both sides are reloaded." Every time it comes back, the code is organized to see how it is down. Apart from this I already know that random works. Any help will be greatly appreciated. Thank you.

  var reload = function () {var random = function () {var randomizer = Math.random () * 100 if (randomizer & lt; = 33) {var compDecision = 1} Else If (randomizer> 67) {var compDecision = 2} and if (33 & lt; randomizer & randomizer & lt; = 67) {var compDecision = 3}} if (compDecision = 1) {confirm ("both Confirm the sides (Compdecision = 2) ("You reload and raise the defensive positions of the enemy.")} And if (compDecision = 3) {Confirm ("The enemy takes you out as the reload . "}}}  

= , And logical comparison For operation, == then you should declare the var compdecision as blank or default var followed by var . I recommend terminating your statement using the semi-colon ; , unlike JavaScript, they are not optional for other languages I'm your work code, look at the end of the solution:

  var reload = function () {v Ar compDecision = 0; Var random2 = function () {var randomizer = Math.random () * 100 if (randomizer & lt; = 33) {compDecision = 1; } Else if (randomizer> 67) {compDecision = 2; } And {compDecision = 3; }} Random2 (); If (compdeecision == 1) {warning ("reload both sides."); } And if (compdeecision == 2) {warnings ("You reload and takes enemy defensive position."); } And if (compdeecision == 3) {Warning ("The enemy takes you out as the reload."); }} Reload ();  

Tested here:


No comments:

Post a Comment