Created
April 11, 2017 23:22
-
-
Save gpuido/53478957cdcdd310386f08ed0fd47954 to your computer and use it in GitHub Desktop.
This file contains 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
function InsertCharacter ( str, totalLength, char=" " ) | |
{ | |
str = str + "" | |
if ( str.length >= totalLength ) {} | |
else { while (str.length < totalLength) { str += char} } | |
return str | |
} | |
ConsoWatt = {} | |
ConsoWatt.Pad = 20 | |
ConsoWatt.Currency = "€" | |
ConsoWatt.kWhCost = 0.14490 // € | |
ConsoWatt.Day = function Day ({ watts=0, hours=0, count=1}) | |
{ | |
let totalWatts = watts * count | |
let totalDay = ( (totalWatts / 1000.0) * hours * ConsoWatt.kWhCost) | |
let str = InsertCharacter("consumption",ConsoWatt.Pad) | |
str += count +" x " | |
str += watts +" watts " | |
str += "for " + hours +" hours " | |
console.log (str) | |
console.log (InsertCharacter("day",ConsoWatt.Pad) + totalDay + " " + ConsoWatt.Currency ) | |
return totalDay | |
} | |
ConsoWatt.Month = function Month ({ watts=0, hours=0, count=1}) | |
{ | |
let totalMonth = ConsoWatt.Day({ watts, hours, count}) * 30.0 | |
console.log (InsertCharacter("month",ConsoWatt.Pad)+totalMonth + " " + ConsoWatt.Currency ) | |
} | |
ConsoWatt.Year = function Year ({ watts=0, hours=0, count=1}) | |
{ | |
let totalYear = ConsoWatt.Day({ watts, hours, count}) * 365.0 | |
console.log (InsertCharacter("year",ConsoWatt.Pad)+totalYear + " " + ConsoWatt.Currency ) | |
} | |
ConsoWatt.Year ({ watts:120, hours:24, count:1}) // computer | |
// ConsoWatt.Day ({ watts:120, hours:24, count:1}) | |
// ConsoWatt.Month ({ watts:20, hours:16, count:1}) | |
process.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment