diff --git a/index.html b/index.html index e69de29..5115f41 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,49 @@ + + + + + Cash Register + + + +
+
+
+

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

+ +

+
+
+ + + + + \ No newline at end of file diff --git a/js/calculator.js b/js/calculator.js index e69de29..a6b92fa 100644 --- a/js/calculator.js +++ b/js/calculator.js @@ -0,0 +1,34 @@ +function calculatorModule() { + + var calculator = { + total: 0, + + clear: function (){ + this.total = 0; + }, + + add: function (x){ + return this.total += x; + }, + + subtract: function (x){ + return this.total -= x; + }, + + divide: function (x){ + return this.total /= x; + }, + + multiple: function (x){ + return this.total *= x; + }, + + equals: function (x){ + return this.total; + }, + +}; +return calculator; +} + + diff --git a/js/cash_register.js b/js/cash_register.js index e69de29..5fc183f 100644 --- a/js/cash_register.js +++ b/js/cash_register.js @@ -0,0 +1,116 @@ +var operations = calculatorModule(); + + + +window.register = (function () { + // var mycalc = cashRegistorModule(); + // console.log(mycalc.getBalance()); + + var display = document.getElementById("d"); + document.getElementById('btn7').addEventListener("click", function(){ + display.innerHTML += 7; + }); + + document.getElementById('btn8').addEventListener("click", function(){ + display.innerHTML+= 8; + }); + + document.getElementById('btn9').addEventListener("click", function(){ + display.innerHTML += 9; + }); + + document.getElementById('btn4').addEventListener("click", function(){ + display.innerHTML += 4; + }); + + document.getElementById('btn5').addEventListener("click", function(){ + display.innerHTML += 5; + }); + + document.getElementById('btn6').addEventListener("click", function(){ + display.innerHTML += 6; + }); + + document.getElementById('btn1').addEventListener("click", function(){ + display.innerHTML += 1; + }); + document.getElementById('btn2').addEventListener("click", function(){ + display.innerHTML += 2; + }); + document.getElementById('btn3').addEventListener("click", function(){ + display.innerHTML += 3; + }); + + document.getElementById('btn0').addEventListener("click", function(){ + display.innerHTML += 0; + }); + document.getElementById('btn00').addEventListener("click", function(){ + display.innerHTML += '00'; + }); + document.getElementById('desml').addEventListener("click", function(){ + display.innerHTML += '.'; + }); + document.getElementById('add').addEventListener("click", function(){ + console.log(display.innerHTML); + var x = display.innerHTML; + var value = operations.add(x); + console.log(value); + }); + document.getElementById('wdcash').addEventListener("click", function(){ + return cashRegistorModule.withdrawCash; + }); + // document.getElementById('equals').addEventListener("click", function(){ + // return operations.equals; + // }); + document.getElementById('divide').addEventListener("click", function(){ + return operations.divide; + }); + + // document.getElementById('clear').addEventListener("click", function(){ + // return operations.clear; + // }); + document.getElementById('mlti').addEventListener("click", function(){ + return operations.multiple; + }); + document.getElementById('getbal').addEventListener("click", function(){ + return cashRegistorModule.getBalance; + }); + document.getElementById('subtr').addEventListener("click", function(){ + return operations.subtract; + }); + document.getElementById('depcash').addEventListener("click", function(){ + return cashRegistorModule.depositCash; + }); + + function concatenateNumbers (number){ + if(display.innerHTML != " "){ + display.innerHTML += number; + }else { + console.log ("Empty"); + display.innerHTML = number; + } + } + function cashRegistorModule (){ + var cashreg; + LastOperator = " "; + + var cashRegistor1 = { + cashreg: 0, + + depositCash: function (){ + operations.total = cashreg; + }, + + withdrawCash: function(){ + operations.total = 0; + cashreg = 0; + }, + getBalance: function (){ + return operations.equals; + } + }; + return cashRegistor1; + } + })(); + +console.log('test');