JSFiddle - React, Tailwind, and code Playground

by Jessie Lau

JavaScript

function changePowerTotal(totalPowerGenerated,
        currentGeneratorID,
        generatorStatus,
        amountPowerProducedByCurrentGenerator)
{
    if(generatorStatus == "on"){
      totalPowerGenerated += amountPowerProducedByCurrentGenerator;
        alert("Generator #" 
              + currentGeneratorID 
              + " is now on, adding " + amountPowerProducedByCurrentGenerator 
              + " MW, for a total of " + totalPowerGenerated + " MW!");
    }
    else if(generatorStatus == "off"){
    totalPowerGenerated -= amountPowerProducedByCurrentGenerator;
        alert("Generator #" 
              + currentGeneratorID 
              + " is now off, removing " + amountPowerProducedByCurrentGenerator 
              + " MW, for a total of " + totalPowerGenerated + " MW!");
    }
    return totalPowerGenerated;
};