Created
July 25, 2014 08:56
-
-
Save macikokoro/a6403088775625a082f5 to your computer and use it in GitHub Desktop.
Using a for loop to print out different states of a generator: off, on, power generated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var totalGen = 19; | |
var totalMW = 0; | |
var totalGen = 19; | |
var totalMW = 0; | |
for (var gen = 1; gen <= totalGen; gen++) { | |
if (gen % 2 != 0) { | |
console.log("Generator #" + gen + " is off."); | |
} else if (gen % 2 === 0 && gen <= 4) { | |
totalMW += 62; | |
console.log("Generator #" + gen + " is on, adding 62 MW, for a total of " + totalMW + " MW!"); | |
} else { | |
totalMW += 124; | |
console.log("Generator #" + gen + " is on, adding 124 MW, for a total of " + totalMW + " MW!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment