Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.