File tree 1 file changed +14
-1
lines changed
src/WinXP/apps/Calculator
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,14 @@ export default function Calculator({ onClose }) {
12
12
const [ auxValue , setAuxValue ] = useState ( emptyValue ) ;
13
13
const [ currentOperation , setCurrentOperation ] = useState ( null ) ;
14
14
const [ operationClicked , setOperationClicked ] = useState ( false ) ;
15
+ const [ divisionByZeroCounter , setDivisionByZeroCounter ] = useState ( 0 ) ;
16
+ const divisionByZeroMessages = [
17
+ 'Cannot divide by zero' ,
18
+ 'I still cannot divide by zero' ,
19
+ 'Repeteadly trying won\'t change this!' ,
20
+ 'Stop already! You\'re scaring the ALU.' ,
21
+ 'Alright, do whatever you want.'
22
+ ] ;
15
23
16
24
function hoverOption ( option ) {
17
25
if ( openOption ) setOpenOption ( option ) ;
@@ -72,7 +80,12 @@ export default function Calculator({ onClose }) {
72
80
case '/' :
73
81
if ( b === 0 ) {
74
82
// Division by zero
75
- setCurrentValue ( 'Cannot divide by zero.' ) ;
83
+ if ( divisionByZeroCounter < divisionByZeroMessages . length ) {
84
+ setCurrentValue ( divisionByZeroMessages [ divisionByZeroCounter ] ) ;
85
+ setDivisionByZeroCounter ( divisionByZeroCounter + 1 ) ;
86
+ break ;
87
+ }
88
+ setCurrentValue ( divisionByZeroMessages [ 0 ] ) ;
76
89
break ;
77
90
}
78
91
setCurrentValue ( a / b ) ;
You can’t perform that action at this time.
0 commit comments