Instantly share code, notes, and snippets.

@heypaulmcgrath /calculator.js Secret
Last active Sep 29, 2018

Embed
What would you like to do?
"use strict";
const toTwoPlaces = (x) => {
return Math.round( x * 1e2 ) / 1e2;
}
function calculate() {
const a = toTwoPlaces(document.getElementById("a").value);
const b = toTwoPlaces(document.getElementById("b").value);
const z = toTwoPlaces(document.getElementById("z").value);
const x = (a / (a + b));
const y = (b / (a + b));
const yourExpenses = toTwoPlaces((x * z));
const partnerExpenses = toTwoPlaces((y * z));
document.getElementById("result").style.visibility = "visible";
document.getElementById("you").innerHTML = "Your share: " + yourExpenses;
document.getElementById("yourPartner").innerHTML = "Your partner's share: " + partnerExpenses;
document.getElementById("calculate-button").value = "recalculate";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment