Skip to content

Instantly share code, notes, and snippets.

@benhodgson87
Last active May 31, 2018 19:03
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 benhodgson87/5e0930939e9191580a1261904e07afe0 to your computer and use it in GitHub Desktop.
Save benhodgson87/5e0930939e9191580a1261904e07afe0 to your computer and use it in GitHub Desktop.
Bottle Status Logic
// source http://jsbin.com/mokikomobe
const current_bottle_weight = 1120;
const empty_bottle_weight = 649;
const full_bottle_weight = 1357;
const full_bottle_ml = 700;
const full_bottle_volume = full_bottle_weight - empty_bottle_weight;
const current_bottle_volume = current_bottle_weight - empty_bottle_weight;
// Calculate current percentage in bottle
const current_bottle_percentage = current_bottle_volume * (100 / full_bottle_volume)
// Calculate bottle volume in ml
const current_bottle_ml = (full_bottle_ml / 100) * current_bottle_percentage
console.log(`This bottle is ${Math.round(current_bottle_percentage)}% full, and has ${Math.round(current_bottle_ml / 10) * 10}ml remaining.`)
// This bottle is 67% full, and has 470ml remaining.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment