Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Last active January 5, 2016 03:40
Show Gist options
  • Save dhigginbotham/7ef11c0b60611bbe5211 to your computer and use it in GitHub Desktop.
Save dhigginbotham/7ef11c0b60611bbe5211 to your computer and use it in GitHub Desktop.
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()}();
(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