Last active
May 31, 2018 19:03
-
-
Save benhodgson87/5e0930939e9191580a1261904e07afe0 to your computer and use it in GitHub Desktop.
Bottle Status Logic
This file contains hidden or 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
// 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