Last active
January 5, 2016 03:40
-
-
Save dhigginbotham/7ef11c0b60611bbe5211 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
javascript:!function(){function t(t,r){return t/r}function r(r,n){return t(r,n)*r}function n(){var n=window.prompt("Voltage?",4.2),o=window.prompt("Ohms?",.2);if(isNaN(n)&&(n=parseInt(n)),isNaN(o)&&(o=parseInt(o)),n&&o){var i="Stats:\r";i+="Amps: "+t(n,o).toFixed(2)+"\r",i+="Ohms: "+o+"\r",i+="Volts: "+n+"\r",i+="Watts: "+r(n,o).toFixed(2)+"\r",window.alert(i)}}n()}(); |
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() { | |
function ampify(v, r) { | |
return v / r; | |
} | |
function wattify(v, r) { | |
return ampify(v,r) * v; | |
} | |
function init() { | |
var volts = window.prompt('Voltage?', 4.2); | |
var ohms = window.prompt('Ohms?', .2); | |
if (isNaN(volts)) volts = parseInt(volts); | |
if (isNaN(ohms)) ohms = parseInt(ohms); | |
if (volts && ohms) { | |
var alertText = 'Stats:\r'; | |
alertText += 'Amps: ' + ampify(volts, ohms).toFixed(2) + '\r'; | |
alertText += 'Ohms: ' + ohms + '\r'; | |
alertText += 'Volts: ' + volts + '\r'; | |
alertText += 'Watts: ' + wattify(volts, ohms).toFixed(2) + '\r'; | |
window.alert(alertText); | |
} | |
} | |
init(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment