Skip to content

Instantly share code, notes, and snippets.

@pedromcunha
Created July 28, 2014 20:52
Show Gist options
  • Save pedromcunha/e773e63b205f0edf567d to your computer and use it in GitHub Desktop.
Save pedromcunha/e773e63b205f0edf567d to your computer and use it in GitHub Desktop.
function changePowerTotal(currentPower, GenID, GenStat, GenPower) {
if(GenStat == 'on') {
currentPower += GenPower;
return alert("Generator #"+GenID+" is now on adding "+GenPower+" MW, for a total of "+currentPower+" MW!");
}
else if(GenStat == 'off') {
if (currentPower <= 0) {
currentPower = 0;
}
else {
currentPower -= GenPower;
}
return alert("Generator #"+GenID+" is now off, removing "+GenPower+" MW, for a total of "+currentPower+" MW!");
}
return currentPower;
}
changePowerTotal(0, 2, "off", 62);
@pedromcunha
Copy link
Author

Code Academy Power Generator problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment