Skip to content

Commit

Permalink
changed screen display to show minus sign instead of n. decoupled int…
Browse files Browse the repository at this point in the history
…ernal screeninput from the screeninput which is displayed.
  • Loading branch information
angaaruriakhil committed Sep 26, 2021
1 parent 8f72040 commit 3ff940d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
31 changes: 19 additions & 12 deletions dist/main.dev.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use strict";

var screenInput = document.querySelector("#screenInput");
var screenOutput = document.querySelector("#screenOutput"); // Special Button Functionality - Functions
var screenInputDisplay = document.querySelector("#screenInput");
var screenOutput = document.querySelector("#screenOutput");
var screenInput = ""; // Special Button Functionality - Functions

function calculateAnswer() {
var screenInputArray = screenInput.innerText.split(/[n+\-/*]/); // The split needs to allow for numbers with more than one digit. Therefore a split is used.
var screenInputArray = screenInput.split(/[n+\-/*]/); // The split needs to allow for numbers with more than one digit. Therefore a split is used.
// As the split changes "n", which represents a negative number, to "", we need to switch it back to "n" in screenInputArray using a map loop.

var completeScreenInputArray = screenInputArray.map(function (character) {
Expand All @@ -25,8 +26,7 @@ function calculateAnswer() {
}

;
console.log(floatArray);
var operatorArray = screenInput.innerText.match(/[+\-/*]/g);
var operatorArray = screenInput.match(/[+\-/*]/g);
var answer = floatArray[0];

for (var _i = 0; _i < floatArray.length; _i++) {
Expand Down Expand Up @@ -66,28 +66,34 @@ function handleEquals(event) {
}

function handleNegativeNumber() {
screenInput.innerHTML += "n";
screenInputDisplay.innerHTML += "(-)";
screenInput += "n";
}

function handleDecimalInput(event) {
screenInput.innerHTML += event.target.innerHTML;
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
}

function handleDelete() {
screenInput.innerHTML = screenInput.innerText.slice(0, -1);
screenInputDisplay.innerHTML = screenInputDisplay.innerText.slice(0, -1);
screenInput = screenInput.slice(0, -1);
}

function handleOperation(event) {
screenInput.innerHTML += event.target.innerHTML;
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
}

function handleDivide(event) {
screenInput.innerHTML += "/";
screenInputDisplay.innerHTML += "÷";
screenInput += "/";
}

function handleAc() {
screenInput.innerHTML = "";
screenInputDisplay.innerHTML = "";
screenOutput.innerHTML = "";
screenInput = "";
} // Special Button Functionality - Event Listeners


Expand Down Expand Up @@ -123,7 +129,8 @@ function buttonUnpress(event) {

allNumbers.forEach(function (number) {
number.addEventListener("click", function (event) {
screenInput.innerHTML += event.target.innerHTML;
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
});
});
allButtons.forEach(function (button) {
Expand Down
29 changes: 18 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
let screenInput = document.querySelector("#screenInput");
let screenInputDisplay = document.querySelector("#screenInput");
let screenOutput = document.querySelector("#screenOutput");
let screenInput = "";


// Special Button Functionality - Functions

function calculateAnswer() {
let screenInputArray = screenInput.innerText.split(/[n+\-/*]/);
let screenInputArray = screenInput.split(/[n+\-/*]/);
// The split needs to allow for numbers with more than one digit. Therefore a split is used.
// As the split changes "n", which represents a negative number, to "", we need to switch it back to "n" in screenInputArray using a map loop.
const completeScreenInputArray = screenInputArray.map(character => {
Expand All @@ -22,8 +23,7 @@ function calculateAnswer() {
floatArray.push(parseFloat(filteredInputArray[i]));
}
};
console.log(floatArray);
let operatorArray = screenInput.innerText.match(/[+\-/*]/g);
let operatorArray = screenInput.match(/[+\-/*]/g);
let answer = floatArray[0];

for (let i=0; i < floatArray.length; i++) {
Expand Down Expand Up @@ -58,28 +58,34 @@ function handleEquals(event) {
}

function handleNegativeNumber() {
screenInput.innerHTML += "n"
screenInputDisplay.innerHTML += "(-)";
screenInput += "n"
}

function handleDecimalInput(event) {
screenInput.innerHTML += event.target.innerHTML
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
}

function handleDelete() {
screenInput.innerHTML = screenInput.innerText.slice(0, -1);
screenInputDisplay.innerHTML = screenInputDisplay.innerText.slice(0, -1);
screenInput = screenInput.slice(0, -1);
}

function handleOperation(event) {
screenInput.innerHTML += event.target.innerHTML;
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
}

function handleDivide(event) {
screenInput.innerHTML += "/";
screenInputDisplay.innerHTML += "÷";
screenInput += "/";
}

function handleAc() {
screenInput.innerHTML = ""
screenInputDisplay.innerHTML = ""
screenOutput.innerHTML = ""
screenInput = "";
}
// Special Button Functionality - Event Listeners

Expand Down Expand Up @@ -118,7 +124,8 @@ function buttonUnpress(event) {

allNumbers.forEach(number => {
number.addEventListener("click", (event) => {
screenInput.innerHTML += event.target.innerHTML
screenInputDisplay.innerHTML += event.target.innerHTML;
screenInput += event.target.innerHTML;
})
})

Expand Down

0 comments on commit 3ff940d

Please sign in to comment.