Skip to content

Instantly share code, notes, and snippets.

@mchayapol
Created September 15, 2015 03:16
Show Gist options
  • Save mchayapol/6c1d99697d9e60ae6324 to your computer and use it in GitHub Desktop.
Save mchayapol/6c1d99697d9e60ae6324 to your computer and use it in GitHub Desktop.
CashRegister example with docket
function calculateChange() {
var purchase = document.getElementById('purchase');
var cash = document.getElementById('cash');
var change = document.getElementById('change');
var result = Number(cash.value) - Number(purchase.value);
console.log(result);
change.value = result;
// Update docket
var dPurchase = document.getElementById('dPurchase');
var dCash = document.getElementById('dCash');
var dChange = document.getElementById('dChange');
var dVat = document.getElementById('dVat');
dPurchase.innerHTML = purchase.value;
dCash.innerHTML = cash.value;
dChange.innerHTML = change.value;
dVat.innerHTML = (purchase.value * 7 / 107).toPrecision(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment