Skip to content

Instantly share code, notes, and snippets.

@ferdelamad
Created August 27, 2018 16:58
Show Gist options
  • Save ferdelamad/d8b44681bed6004bcedc97cecd11d868 to your computer and use it in GitHub Desktop.
Save ferdelamad/d8b44681bed6004bcedc97cecd11d868 to your computer and use it in GitHub Desktop.
Cashinator 3000
var Cashinator3000 = (priceList, startingAmount = 0, salesTax = 0.0725) => {
this.priceListCSV = priceList;
this.startingAmount = startingAmount;
this.salesTax = salesTax;
this.transactions = [];
this.transactionId = 0;
};
Cashinator3000.prototype.currentBalance = () => {
return this.startingAmount;
};
Cashinator3000.prototype.transaction = () => {
var tax = this.salesTax;
var id = this.transactionId;
var transaction = {};
transaction.id = id;
transaction.time = new Date();
transaction.items = [];
transaction.subtotal = 0;
transaction.tax = tax;
transaction.getTotal = () => {
const tax = this.subtotal * this.tax;
this.total = this.subtotal + tax;
return this.total;
};
transaction.total = 0;
this.transactions[this.transactionId] = transaction;
};
Cashinator3000.prototype.scan = item => {
this.transactions[this.transactionId].items.push(item);
const customerMsg = `Item: ${item}, Sub-total: ${
this.transactions[this.transactionId].subtotal
}.`;
console.log(customerMsg);
return customerMsg;
};
Cashinator3000.prototype.cashOut = moneyIn => {
//close the transaction (pop from the queue);
this.transactionId++;
console.log(`Transaction No. ${this.transactionId - 1} is closed.`);
//calculate change (min number of bills and coins)
//show change
//show gran total
const granTotal = this.transactions[this.transactionId - 1].get();
console.log(`Your gran total is: ${granTotal}`);
return granTotal;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment