Skip to content

Commit

Permalink
Calculator: Easter egg in "division by zero" messages. Proposed by @g…
Browse files Browse the repository at this point in the history
  • Loading branch information
matricali committed Apr 13, 2019
1 parent 41d0bd9 commit a92535e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/WinXP/apps/Calculator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export default function Calculator({ onClose }) {
const [auxValue, setAuxValue] = useState(emptyValue);
const [currentOperation, setCurrentOperation] = useState(null);
const [operationClicked, setOperationClicked] = useState(false);
const [divisionByZeroCounter, setDivisionByZeroCounter] = useState(0);
const divisionByZeroMessages = [
'Cannot divide by zero',
'I still cannot divide by zero',
'Repeteadly trying won\'t change this!',
'Stop already! You\'re scaring the ALU.',
'Alright, do whatever you want.'
];

function hoverOption(option) {
if (openOption) setOpenOption(option);
Expand Down Expand Up @@ -72,7 +80,12 @@ export default function Calculator({ onClose }) {
case '/':
if (b === 0) {
// Division by zero
setCurrentValue('Cannot divide by zero.');
if (divisionByZeroCounter < divisionByZeroMessages.length) {
setCurrentValue(divisionByZeroMessages[divisionByZeroCounter]);
setDivisionByZeroCounter(divisionByZeroCounter + 1);
break;
}
setCurrentValue(divisionByZeroMessages[0]);
break;
}
setCurrentValue(a / b);
Expand Down

1 comment on commit a92535e

@VocalFan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ayy

Please sign in to comment.