Skip to content

Instantly share code, notes, and snippets.

@dillonchr
Created December 1, 2021 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dillonchr/0d2f9cd14985e45757dd1bdbdcfd3b5c to your computer and use it in GitHub Desktop.
Save dillonchr/0d2f9cd14985e45757dd1bdbdcfd3b5c to your computer and use it in GitHub Desktop.
water weight
(function(weight) {
// how much water weighs per gallon
const WATER_WEIGHT_IN_POUNDS_PER_GALLON = 8.34;
// how much of the body is made of water
const WATER_PERCENTAGE_IN_BODY = 0.6;
function getGallonsOfWater(weight) {
return weight * WATER_PERCENTAGE_IN_BODY / WATER_WEIGHT_IN_POUNDS_PER_GALLON;
}
function getPoundsFromGallons(gallons) {
// since water is 60%, we need to figure out the other 40%
// so we just find one third of 60% (20%) and then double that
// to find 40% and add the two together to uncover what the original
// weight was
const oneThird = gallons / 3;
return (gallons + (oneThird * 2)) * WATER_WEIGHT_IN_POUNDS_PER_GALLON;
}
console.clear();
console.log({
weight,
gallons: getGallonsOfWater(weight),
andBack: getPoundsFromGallons(getGallonsOfWater(weight))
});
}
)(200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment