How jeswanthjohn/vanilla-js-calculator works
Project type and purpose
• This is a single-page, frontend-only “Vanilla JS Calculator” built with plain HTML, CSS, and JavaScript.
• Its purpose is to demonstrate DOM manipulation, input validation, keyboard accessibility, and user feedback without any external frameworks.
File structure
• Top-level files:
• index.html – Defines the calculator’s UI structure (buttons, inputs, result display).
• styles.css – Contains layout rules, responsive breakpoints, and interaction feedback styles.
• app.js – Houses the event listeners, input validation logic, arithmetic operations, edge-case handling, and DOM updates.
• README.md – Project overview, features, tech stack, and potential enhancements.
• No backend, no database, no external service integrations—this is a pure client-side widget.
README for additional insights
• Emphasizes clear separation of concerns (HTML for structure, CSS for style, JS for logic).
• Lists supported operations, keyboard shortcuts, and error-handling features.
• Mentions responsive design and potential future enhancements (history, themes, scientific ops).
Main components and interactions
a. User (Browser)
b. UI Layer (index.html + styles.css)
– Input fields & buttons
– Result / error display
c. JavaScript Logic Layer (app.js)
– Event Handlers (click, keypress)
– Validation Module (NaN, Infinity, divide-by-zero)
– Calculation Module (add, subtract, multiply, divide)
– Formatter (rounding decimals)
– DOM Updater (inject result or error messages)
Relationships / data flow:
User Action → UI Layer → Event Handlers → Validation → Calculation → Formatter → DOM Updater → UI Layer → User Feedback
Architectural patterns and design principles
• Separation of concerns: UI vs. styling vs. logic.
• Modular functions in app.js (validation, calculation, formatting).
• Unidirectional data flow: user input → processing → UI update.
• Progressive enhancement: keyboard support layered on top of click events.