Skip to content

Commit

Permalink
Add clear numbers functinality
Browse files Browse the repository at this point in the history
  • Loading branch information
gabs712 committed Feb 11, 2024
1 parent a3041a0 commit 97e21aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<button class="subtract operator" value="-">-</button>
<button class="clear" value="clear">C</button>
<button class="number" value="0">0</button>
<button class="equals" value="">=</button>
<button class="equals" value="=">=</button>
<button class="add operator" value="+">+</button>
</div>
</div>
Expand Down
33 changes: 32 additions & 1 deletion scrpit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
// limit to 9 characters
const VISOR_REGISTER = document.querySelector('.register')
const VISOR_OPERATION = document.querySelector('.operation')
const BUTTONS = document.querySelectorAll('.grid button')

const CURRENT_OPERATION = []

BUTTONS.forEach((button) => button.addEventListener('click', ManageOperations))

function ManageOperations(e) {
const button = e.target
if (button.classList.contains('number')) {
populateVisorOperation(button)
} else if (button.classList.contains('clear')) {
clearNumbers()
} else if (button.classList.contains('operator')) {

}
}

function populateVisorOperation(button) {
if (CURRENT_OPERATION.length < 9) {
CURRENT_OPERATION.push(button.value)
VISOR_OPERATION.textContent = CURRENT_OPERATION.join('')
}
}

function clearNumbers() {
if (CURRENT_OPERATION.length > 0) {
CURRENT_OPERATION.splice(0)
VISOR_OPERATION.textContent = ''
VISOR_REGISTER.textContent = ''
}
}

function operate(n1, operator, n2) {
if (operator === '+') add(n1, n2)
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body {
padding: 18px;
display: flex;
flex-direction: column;
gap: 19px;
gap: 18px;
box-shadow: 8px 8px 3px rgba(0, 0, 0, 0.25);
}
.visor {
Expand Down

0 comments on commit 97e21aa

Please sign in to comment.