diff --git a/public/calculator.html b/public/calculator.html index 65321f9..790d11e 100644 --- a/public/calculator.html +++ b/public/calculator.html @@ -7,6 +7,7 @@ +
@@ -27,7 +28,7 @@
-
+
@@ -45,10 +46,10 @@
-
-
-
-
+
+
+
+
diff --git a/src/calculator.css b/src/calculator.css index ac28bc6..62fc11b 100644 --- a/src/calculator.css +++ b/src/calculator.css @@ -17,6 +17,8 @@ body { flex-direction: column; background: black; height: 85vh; + max-height: 750px; + min-height: 475px; width: 25vw; min-width: 20vw; margin-top: 1vh; @@ -53,7 +55,7 @@ body { } .buttons button { - height:50px; + height: 50px; width: 50px; border: 1px solid; border-radius: 50%; diff --git a/src/calculator.js b/src/calculator.js index e69de29..0bcd9b3 100644 --- a/src/calculator.js +++ b/src/calculator.js @@ -0,0 +1,76 @@ +window.addEventListener('load', (event) => { + if(sessionStorage.getItem('calculatorMemory')){ + sessionStorage.removeItem('calculatorMemory') + } + if (!sessionStorage.getItem('calculatorMemory')){ + sessionStorage.setItem('calculatorMemory', { + last: null, + lastIndex: 0, + statement: [], + operands: ['+', '-', '/', '*', '(', ')', '^'] + }); + // example storage: + // {statementIndex:#, statement: [111, '+', 222, '*', '(', 333, '/', 444, ')'], ? } + //there may be an easier way to do this? + } + if (!sessionStorage.getItem('calculatorMemoryHistory')){ + //store calculatorMemory history - limit to 5? + sessionStorage.setItem('calculatorMemoryHistory', {}) + } + //I can see how React would thrive here lol +}); + +const addNumeral = function(x){ + const {last, lastIndex, statement, operands} = sessionStorage.getItem('calculatorMemory'); + if (typeof(last) == 'number' && typeof(x) == 'number'){ + last = Number([statement[lastIndex], x].join('')); + statement[lastIndex] = last; + } else if (operands.includes(last) && typeof(x) == 'number'){ + statement.push(x); + last = x; + lastIndex = statement.length - 1; + } else if (operands.includes(last) && operands.includes(x)){ + statement[lastIndex] = x + last = x; + //lastIndex stays the same + } + sessionStorage.setItem('calculatorMemory', { + last, + lastIndex, + statement, + operands + }) + let expressionDisplay = document.getElementsByClassName("expression") + expressionDisplay.innerText = statement.join('') +}; + +const addOperand = function(operand){ + console.log(operand) +}; + +//Pseudocode first + +/* +//button clicked 'x' (for most buttons) +if last item and x are both numbers + concat last item and x in memory + set concat as last + +if last item is an operator and x is a number + push x into statement +if last item and x are both operators + x replaces last item +end +set session storage +update display + +//button clicked 'equals' --recursive oppertunity +//order of opperations -carefuly + does statement contain a '(', if so, and more than one, find last + --assuming closing ')' at end if none supplied, maybe add them in? + calculate inside +*/ + + +// -- documentation +//store last 'operation' \ No newline at end of file