Skip to content

Commit 42e281d

Browse files
committed
added error feature
1 parent fd23f31 commit 42e281d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

javaScriptCalculator/script.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,24 @@ class Calculator {
6666
this.leaveZero();
6767
}
6868

69+
// not wroking
6970
backOne() {
7071
this.state.monitor.pop();
7172
this.state.output = this.state.monitor.join("");
7273
this.render();
73-
console.log(this.state)
74+
console.log(this.state.monitor)
75+
if (this.state.output === "") {
76+
this.state.output = "0";
77+
}
7478
}
7579

7680
total() {
77-
const total = eval(this.state.monitor.join(""));
81+
// give something wrong and see how it works
82+
try{
83+
var total = eval(this.state.monitor.join(""));
84+
}catch(e){
85+
total = e;
86+
}
7887

7988
this.state = {
8089
output: total,

0 commit comments

Comments
 (0)