Skip to content

Commit

Permalink
add comments in calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelefavero committed Mar 6, 2024
1 parent bec195c commit a7c2a57
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion calculator.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@
<script>
// TODO shrink display text size when there are more than 6 numbers and so on (use display.innerText.length)

// * Variables
const display = document.getElementById('display')
const operatorButtons = document.querySelectorAll('.operator')
let firstValue = 0
let secondValue = 0
let operator = ''
let operatorSelected = false

// * APPEND NUMBER
function appendNumber(number) {
if (display.innerText === 'Error') {
display.innerText = '0'
Expand All @@ -140,15 +142,16 @@
resetOperatorColor()
}

// * SELECT OPERATOR
function selectOperator(selectedOperator) {
firstValue = parseFloat(display.innerText)
operator = selectedOperator
// display.innerText = '0'
operatorSelected = true

changeOperatorColor()
}

// * CALCULATE
function calculate() {
secondValue = parseFloat(display.innerText)

Expand Down Expand Up @@ -179,6 +182,7 @@
changeOperatorColor()
}

// OTHER FUNCTIONS
function percentage() {
display.innerText = parseFloat(display.innerText) / 100
}
Expand All @@ -200,6 +204,7 @@
resetOperatorColor()
}

// * OPERATOR BUTTONS COLORS
function changeOperatorColor() {
operatorButtons.forEach((button) => {
if (button.innerText === operator) {
Expand Down

0 comments on commit a7c2a57

Please sign in to comment.