Skip to content

Instantly share code, notes, and snippets.

@macikokoro
Created July 25, 2014 08:56
Show Gist options
  • Save macikokoro/a6403088775625a082f5 to your computer and use it in GitHub Desktop.
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.
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