The UI is shamelessly inspired by the iOS calculator app. 📱
A sleek and user-friendly calculator app built with HTML, CSS, and JavaScript. This app is designed to handle basic arithmetic operations and some unique functionalities with an intuitive interface.
- Basic arithmetic operations: Addition, Subtraction, Multiplication, and Division.
- Support for sign (+/-) change and percentage (%) calculations.
- Keyboard support for all operations. ⌨️
- Adaptive display font-size.
Your feedback/criticism is welcome 😊.
The application leverages a stack-based logic to process user inputs and calculate results dynamically:
- Input Buffering: User inputs are held in a buffer until an operand key is pressed.
- Operand Key Press Handling:
- Upon pressing an operand key, it's pushed to the stack.
- The stack is then evaluated to resolve the expression at the top.
- Stack Evaluation:
- Evaluation is based on the latest operand key pressed.
- Operations consider up to the last three elements in the stack for calculation.
- Special Operand Keys:
- Keys like '+', '-', 'x', '/', and '=' trigger calculations on the stack.
- Sign('+/-') and percent('%') keys perform immediate calculations on the last number without full stack evaluation.
- Operations are performed based on the stack's current state, with four main scenarios considered for evaluation:
- Triple number sequence: The last number is returned as the new stack.
- Number-Number-Operand sequence: The second number is kept for further operations.
- Operand-Number-Number sequence: Ignores the first operand, focusing on the last number.
- Number-Operand-Number sequence: Performs the operation and updates the stack with the result.
🚀 The code is heavily commented for understanding and collaboration.