A sleek, responsive web calculator built with pure Vanilla JavaScript. It features a modern CSS Grid interface, comprehensive keyboard accessibility, and dynamic event handling.
[Live Demo Link Here] (Consider deploying to GitHub Pages and adding the link!)
(Add a screenshot or GIF of your calculator working here)
<img src="link-to-your-image.png" alt="Calculator UI Preview" width="400">
- Complete Keyboard Integration: Fully mapped to physical keyboard events. Supports numbers, numpad operators (
+,-,*,/),Enterfor calculation,Backspacefor delete, andEscapeto clear. - Responsive CSS Grid: The UI utilizes a scalable CSS Grid architecture, ensuring buttons are perfectly aligned and adapt gracefully to different screen sizes.
- Smart Input Handling: * Automatically prevents multiple leading zeros.
- Replaces common typos (like typing
xinstead of*) behind the scenes. - Validates decimal placement to prevent malformed numbers.
- Replaces common typos (like typing
- Safe Error Handling: Implements
try...catchblocks to gracefully handle invalid mathematical expressions (e.g.,5++5) without crashing the application.
This project was built to demonstrate core DOM manipulation and efficient JavaScript design patterns without relying on external libraries.
- Event Delegation: Instead of attaching an event listener to every single button, the calculator attaches a single listener to the parent
.buttons-gridcontainer. This is significantly better for performance and memory management. - Native Parsing: Mathematical logic is processed using JavaScript's native capabilities, with careful string sanitization applied before evaluation.
- Clone the repository:
git clone https://github.com/pr0-gramm3r/Calculator.git
- Navigate to the directory:
cd Calculator - Run the application:
Simply double-click the
index.htmlfile to open it in your default web browser. No local server or build tools are required.
You can interact with the calculator in two ways:
- Mouse/Touch: Click the UI buttons directly.
- Keyboard: - Type numbers directly.
- Use
Enteror=to get the result. - Use
Backspaceto delete the last character. - Use
Escapeto clear the entire screen (AC).
- Use
- Add a "Dark Mode" toggle.
- Implement a calculation history log.
- Build a custom parser to replace
eval()for enterprise-level security.
Designed and developed by pr0-gramm3r.
- Copy the text above.
- Create a file named
README.mdin yourproject_3folder. - Paste the text in.