Elffuss BraidHub

kikocis/continue public

main · 1.2 KiBRawPermalink
1class Calculator {
2 constructor() {
3 this.result = 0;
4 }
5
6 add(number) {
7 this.result += number;
8 return this;
9 }
10
11 subtract(number) {
12 this.result -= number;
13 return this;
14 }
15
16 multiply(number) {
17 this.result *= number;
18 return this;
19 }
20
21 divide(number) {
22 if (number === 0) {
23 throw new Error("Cannot divide by zero");
24 }
25 this.result /= number;
26 return this;
27 }
28
29 getResult() {
30 return this.result;
31 }
32
33 reset() {
34 this.result = 0;
35 return this;
36 }
37}
38
39---
40
41class Calculator {
42 // ... existing code ...
43
44 exp(number) {
45 this.result = Math.pow(this.result, number);
46 return this;
47 }
48}
49
50---
51
52class Calculator {
53 constructor() {
54 this.result = 0;
55 }
56
57 add(number) {
58 this.result += number;
59 return this;
60 }
61
62 subtract(number) {
63 this.result -= number;
64 return this;
65 }
66
67 multiply(number) {
68 this.result *= number;
69 return this;
70 }
71
72 divide(number) {
73 if (number === 0) {
74 throw new Error("Cannot divide by zero");
75 }
76 this.result /= number;
77 return this;
78 }
79
80 getResult() {
81 return this.result;
82 }
83
84 reset() {
85 this.result = 0;
86 return this;
87 }
88+
89+ exp(number) {
90+ this.result = Math.pow(this.result, number);
91+ return this;
92+ }
93}