From f696e0b255d6ebe3d4d9759b9dbf1f5f26e9f32f Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Tue, 26 Dec 2017 23:26:57 -0800 Subject: [PATCH 1/4] cash register almost done --- js/cash_register.js | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/js/cash_register.js b/js/cash_register.js index e69de29..986ea85 100644 --- a/js/cash_register.js +++ b/js/cash_register.js @@ -0,0 +1,97 @@ + +for(var i = 0; i < 10; i++) { + var btn = document.getElementById("btn" + i); + btn.addEventListener("click", function(event) { + display(event.target.value); + }, false); +} + +var displayElement = document.getElementById("display"); + + +var myCalculator = Calculator(); +var clearDisplay = true; + +var bankBalance = 0; + +function display(val) { + if (clearDisplay) { + clear(); + clearDisplay = false; + } + + displayElement.value += val; +} + +function clear() { + displayElement.value = ''; +} + +function add() { + myCalculator.add(Number(displayElement.value)); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + +function sub() { + myCalculator.subtract(Number(displayElement.value)); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + +function multiply() { + myCalculator.multiply(Number(displayElement.value)); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + +function divide() { + myCalculator.divide(Number(displayElement.value)); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + +function equals() { + myCalculator.getTotal('total'); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + +function clearTotal() { + myCalculator.load(0); + clearDisplay = true; + display(myCalculator.getTotal()); + clearDisplay = true; +} + + +function deposit(amt) { + bankBalance +=amt; + getBalance(); +} + +function withdraw(amt) { + bankBalance -=amt; + getBalance(); +} + +function getBalance() { + clearDisplay = true; + display(bankBalance); + clearDisplay = true; +} + +document.getElementById('addbtn').addEventListener('click', add); +document.getElementById('subbtn').addEventListener('click', sub); +document.getElementById('btnmul').addEventListener('click', multiply); +document.getElementById('divbtn').addEventListener('click', divide); +document.getElementById('equalbtn').addEventListener('click', equals); +document.getElementById('clear').addEventListener('click', clearTotal); +document.getElementById('depbtn').addEventListener('click', deposit); +document.getElementById('balbtn').addEventListener('click', getBalance); +document.getElementById('witbtn').addEventListener('click', withdraw); \ No newline at end of file From 04294d670672b7de0d04d7f879cbcd0e7c3eb3a6 Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Tue, 26 Dec 2017 23:29:14 -0800 Subject: [PATCH 2/4] cash register almost done_html --- index.html | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/index.html b/index.html index e69de29..c958699 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,41 @@ + + + + + + +
+
+ + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + \ No newline at end of file From 228525885295b5d6c02ae30ed984fb1e0ebf3e7d Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Tue, 26 Dec 2017 23:30:19 -0800 Subject: [PATCH 3/4] cash register almost done_calc --- js/calculator.js | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/js/calculator.js b/js/calculator.js index e69de29..c443e1f 100644 --- a/js/calculator.js +++ b/js/calculator.js @@ -0,0 +1,123 @@ +/** + * Declare a function named `calculatorModule` + * this function will have two private variables declared inside of it. + * @variable PRIVATE { Number } `memory` + * @variable PRIVATE { Number } `total` + * @return {object} `calculator` object that can be used + */ +var Calculator = function() { + var memory = 0; + var total = 0; +return { + + + + /** + * sets the `total` to the number passed in + * @param { Number } x + * @return { Number } current total + */ + + +load: (num) => { + if(typeof num === 'number') { + total = num; + return num; + } else { + throw new Error(); + } + }, + + + /** + * Return the value of `total` + * @return { Number } + */ + getTotal: () => { + return total; + }, + + + /** + * Sums the value passed in with `total` + * @param { Number } x + */ + add: (num) => { + if(typeof num === 'number') { + total = total + num; + return total; + } else { + throw new Error(); + } + }, + + /** + * Subtracts the value passed in from `total` + * @param { Number } x + */ + +subtract: (num) => { + if(typeof num === 'number') { + total = total - num; + return total; + } else { + throw new Error(); + } +}, + + /** + * Multiplies the value by `total` + * @param { Number } x + */ +multiply: (num) => { + if(typeof num === 'number') { + total = total * num; + return total; + } else { + throw new Error(); + } +}, + + /** + * Divides the value passing in by `total` + * @param { Number } x + */ + +divide: (num) => { + if(typeof num === 'number') { + total = total / num; + return total; + } else { + throw new Error(); + } +}, + + /** + * Return the value stored at `memory` + * @return { Number } + */ +recallMemory: () => { + return memory; + +}, + + + /** + * Stores the value of `total` to `memory` + */ +saveMemory: () => { + return memory = total; +}, + + /** + * Clear the value stored at `memory` + */ +clearMemory: () => { + return memory = 0; +}, + + /** + * Validation + */ +} +} \ No newline at end of file From fc06a24f7effe3138b53ad7a1c52dbf1bd326fe0 Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Sat, 30 Dec 2017 09:21:20 -1000 Subject: [PATCH 4/4] cash-register almost done --- js/cash_register.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/cash_register.js b/js/cash_register.js index 986ea85..e59ebfb 100644 --- a/js/cash_register.js +++ b/js/cash_register.js @@ -56,6 +56,7 @@ function divide() { } function equals() { + console.log('test') myCalculator.getTotal('total'); clearDisplay = true; display(myCalculator.getTotal()); @@ -71,12 +72,13 @@ function clearTotal() { function deposit(amt) { - bankBalance +=amt; + bankBalance += amt; getBalance(); } function withdraw(amt) { - bankBalance -=amt; + console.log("test") + bankBalance -= amt; getBalance(); }