Calculator Controls
15 min read
Implement Clear
Task
Connect the prepared Clear button to the clear() method you created in Module 1.
Open
Open:
js/ui.js
Add the clear action to the existing button handler.
if (action === 'clear') {
calculator.clear();
}
Then update the display as usual:
updateDisplay();
Test
In the browser:
- Enter
123. - Press
+. - Enter
45. - Press
C.
The display should return to 0.
Use the browser console to confirm that the calculator state has also been reset.
Checkpoint
The Clear control now resets the calculator through one centralized method.