Skip to content

Commit

Permalink
feat(intg): alter entry sign
Browse files Browse the repository at this point in the history
fix #47
  • Loading branch information
lemredd committed Dec 27, 2022
1 parent faf1470 commit 595f2b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/CalculatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const expressionToDisplay = computed(() => {
})
const hasEvaluatedResult = computed(() => previousResult.value === entry.value)
function alterEntrySign() {
if (Number(entry.value) !== 0) {
const negatedEntry = Number(entry.value) * -1
entry.value = String(negatedEntry)
}
}
function appendToEntryScreen(valueToAppend: string|number) {
if (isEntryValueEmpty.value || mustResetOnNextEntry.value) entry.value = String(valueToAppend)
else entry.value += String(valueToAppend)
Expand Down Expand Up @@ -214,7 +221,7 @@ function clearAll() {
<OperationalButton value="+" @append-to-screen="setOperationValue" />
</div>
<div class="row">
<DigitalButton value="+/-" @append-to-screen="appendToEntryScreen" />
<DigitalButton value="+/-" @alter-sign="alterEntrySign" />
<DigitalButton :value="0" @append-to-screen="appendToEntryScreen" />
<DigitalButton value="." @append-to-screen="appendToEntryScreen" />
<EvaluationButton value="=" @append-to-screen="setEvaluationValue" />
Expand Down

0 comments on commit 595f2b1

Please sign in to comment.