A functional calculator built from scratch.
Live Project Demo
The Foundations Calculator is an on-screen calculator crafted with JavaScript, HTML, and CSS as the final project for The Odin Project's Foundations Course. This application demonstrates my mastery of front-end development fundamentals, including DOM manipulation, event handling, and responsive design. It’s a practical tool that performs basic arithmetic operations while handling edge cases with elegance and precision.
- Core Operations: Addition, subtraction, multiplication, and division.
- Intuitive Interface: Buttons for digits (0-9), operators (+, -, *, /), equals (=), and a clear function.
- Real-Time Feedback: Display updates instantly as users input numbers and operators.
- Edge Case Handling: Custom error message for division by zero; prevents incomplete expression evaluation.
- Precision: Rounds long decimal results to avoid display overflow.
- Single-Pair Evaluation: Processes one pair of numbers at a time, mimicking real calculator behavior.
- HTML5: Structures the calculator’s layout and interface.
- CSS3: Delivers a modern, polished design with responsive styling.
- JavaScript: Powers the logic, interactivity, and state management.
Get the calculator running locally in just a few steps:
- Clone the repository:
git clone https://github.com/yourusername/foundations-calculator.git
- Navigate to the project directory:
cd foundations-calculator
- Open
index.html
in your web browser:- Simply double-click the file or use a local server (e.g.,
npx live-server
).
- Simply double-click the file or use a local server (e.g.,
No dependencies required—just pure vanilla code!
- Input Numbers: Click digit buttons (0-9) to build your numbers.
- Select Operator: Choose +, -, *, or / to set the operation.
- Calculate: Press = to see the result.
- Reset: Hit the Clear button to start fresh.
Example: Click 3
, +
, 5
, then =
. The display shows 8
.
This project pushed my skills to new heights. Key takeaways include:
- Operation Logic: Built a robust
operate()
function to handle number-operator-number sequences, ensuring evaluations only trigger with complete expressions. - Edge Cases: Tackled division by zero with a snarky “Nice try!” message and prevented crashes from premature equals presses or consecutive operators.
- UI/UX: Balanced functionality with aesthetics, using CSS to create an intuitive button layout and readable display.
These challenges deepened my expertise in JavaScript event listeners, state management, and CSS grid/flexbox layouts.
- Advanced Functions: Add exponents, square roots, or percentages.
- Keyboard Support: Enable number and operator input via keyboard for accessibility.
- Theming: Introduce light/dark modes or custom styles.
- Calculation History: Store and display past results.
This project is primarily a learning showcase, but I’m open to collaboration! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/awesome-improvement
). - Commit your changes (
git commit -m "Add awesome improvement"
). - Push to your branch (
git push origin feature/awesome-improvement
). - Open a pull request.
This project is released under the MIT License. Feel free to use, modify, or distribute it as you see fit.
Let’s connect!
- Email: garebearcodes@gmail.com
- GitHub: @myopicOracle
- LinkedIn: linkedin.com/in/xiagary