From 907e2889c89b469cf468958636d0214aa02169f8 Mon Sep 17 00:00:00 2001 From: student Date: Thu, 20 Oct 2022 13:02:54 +0200 Subject: [PATCH] Final --- src/components/CalcComp.vue | 87 ++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 21 deletions(-) diff --git a/src/components/CalcComp.vue b/src/components/CalcComp.vue index 31e63a9..892a0ac 100644 --- a/src/components/CalcComp.vue +++ b/src/components/CalcComp.vue @@ -1,25 +1,25 @@ @@ -29,24 +29,60 @@ export default{ return{ current: '', previous: null, - operator: null + operator: null, + operatorClicked: false } }, methods:{ + // vedlejší metody + //vyčičtění + clear() { + this.current = ""; + }, + //přídaní čísla append(number) { - this.current += number; + if (this.operatorClicked) + { + this.current=""; + this.operatorClicked= false; + } + this.current= `${this.current}${number}`; }, + //ošetření vstupu setPrevious(){ this.previous = this.current; - this.current = ''; + this.operatorClicked = true; }, + //Jednotlive operace + //sčítání add() { this.operator = (a,b) => a + b; this.setPrevious(); }, + //Odčítání + minus(){ + this.operator = (a,b) => a - b; + this.setPrevious(); + }, + //Dělení + divide(){ + this.operator = (a,b) => a / b; + this.setPrevious(); + }, + //Násobení + times() { + this.operator = (a,b) => a * b; + this.setPrevious(); + }, + //Procento + procent() { + this.current = this.current / 100; + }, + //VÝSLEDEK equal() { - this.current = this.operator(parseFloat(this.current),parseFloat(this.previous)); - } + this.current = this.operator(parseFloat(this.previous),parseFloat(this.current)); + this.previous = null; + } } } @@ -70,4 +106,13 @@ background-color: lightgray; border: 1px solid gray; } +.nula { + grid-column: 1/3; +} + +.operator { + background-color: orange; + color: whitesmoke; +} + \ No newline at end of file