This project is an enhanced, user-friendly calculator web application built with HTML, CSS, and JavaScript. It provides basic arithmetic operations with improved security, usability, and a sleek, responsive interface.
- Basic arithmetic operations: addition, subtraction, multiplication, and division
- Clear function to reset calculations
- Backspace function to delete the last character
- Decimal point support for floating-point numbers
- Prevention of multiple consecutive operators
- Prevention of multiple decimal points in a single number
- Secure calculation without using unsafe
eval()function - Responsive design for various screen sizes
- Sleek UI with Font Awesome icons
- Improved visual design with gradient backgrounds and smooth animations
calculator/
│
├── index.html
├── calc-style.css
├── main.js
└── README.md
- Clone the repository or download the project files.
- Ensure all files are in the same directory.
- Open
index.htmlin a web browser to use the calculator.
- HTML5
- CSS3
- JavaScript (ES6+)
- Font Awesome (version 6.1.1) for icons
The index.html file contains the structure of the calculator:
- A container div for the entire calculator
- A screen div to display calculations and results
- A buttons container with rows of buttons for numbers and operations
- Semantic class names for better maintainability
The project uses a separate CSS file (calc-style.css) for styling with:
- Modern CSS features (flexbox, gradients, shadows)
- Responsive design for different screen sizes
- Smooth transitions and hover effects
- Consistent spacing and typography
The calculator's functionality is implemented in main.js with:
addToDisplay(value): Adds the clicked number or operator to the display with validationclearAll(): Clears the displaycalcAll(): Safely calculates the result of the expressiondeleteLast(): Removes the last character from the display- Input validation to prevent errors
- Secure calculation without using
eval()
- Replaced unsafe
eval()with a safer Function constructor approach - Added input validation to prevent code injection
- Implemented proper error handling
- To change the styling, modify the
calc-style.cssfile. - To add new functions or modify existing ones, edit the
main.jsfile. - You can replace Font Awesome icons with custom images or different icon sets by modifying the HTML and CSS accordingly.
Contributions to improve the calculator are welcome. Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Make your changes
- Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/improvement) - Create a new Pull Request
This project is open source and available under the MIT License.
For more information or support, please contact the project maintainer.