Skip to content

Commit

Permalink
need to figure out calculator logic still
Browse files Browse the repository at this point in the history
  • Loading branch information
AirTechWick committed Aug 25, 2021
1 parent 5ccc048 commit 285cf5f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Globals
let DISPLAY_VALUE = 0; // default
const displayText = document.querySelector("#displayText");

let FIRST_NUMBER = null;
let SECOND_NUMBER = null;
let OPERATION = null;

function start()
{
Expand Down Expand Up @@ -81,6 +83,8 @@ function populateDisplay()
{
displayText.textContent += DISPLAY_VALUE;
}

saveNumber();
}

function addButtonlisteners()
Expand All @@ -89,7 +93,6 @@ function addButtonlisteners()

let buttonArray = Array.from(buttonNodes);

console.log(buttonArray);

buttonArray.forEach(element => {
element.addEventListener('click', function(e){
Expand All @@ -109,5 +112,30 @@ function addOptionListeners()
});
}

function saveNumber()
{
let secondSaved = false;
const displayString = displayText.textContent;
const operators = ["+","-","x","÷","="];

/// if a user presses an operator save the first number and the operator
// if a user presses "=" operate() on the two numbers
if(!operators.includes(OPERATION))
{
FIRST_NUMBER = displayString.slice(0,-1); // slice from beginning to last number not including operator
OPERATION = displayString[displayString.length - 1];
console.log(FIRST_NUMBER);
console.log(OPERATION);

}

if(operators.includes(OPERATION))
{
displayText = 0
SECOND_NUMBER = displayString;
console.log(SECOND_NUMBER);
}

}

start();

0 comments on commit 285cf5f

Please sign in to comment.