-
-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Description
When the calculator is first loaded or AC/All Clear, if you press the decimal(".") button first, an error occurs on line 27 because the currentOperand is null
TypeError: Cannot read properties of undefined (reading 'includes')
reducer
C:/mystuff/UofU Bootcamp/projects/calculator/src/App.js:27
24 | if (payload.digit === "0" && state.currentOperand === "0") {
25 | return state
26 | }
> 27 | if (payload.digit === "." && state.currentOperand.includes(".")) {
| ^ 28 | return state
29 | }
30 |
This can be fixed by using optional chaining on the currentOperand on line 27:
if (payload.digit === "." && state.currentOperand?.includes(".")) {
STEPS TO REPRODUCE
Load Calculator or Press AC button
Press "."
EXPECTED RESULTS
The calculator display shows "0."
ACTUAL RESULTS
Browser displays error
Metadata
Metadata
Assignees
Labels
No labels