An interactive product customization interface demonstrating real-time DOM manipulation and state-based price calculation.
Fast • Interactive • Vanilla JS
Shopping Cost Calculator is a foundational study in frontend state management without the overhead of modern reactive frameworks (like React or Vue). It simulates a "MacBook Pro" configurator where user choices immediately reflect in the pricing model.
The primary research goal here is to demonstrate Direct DOM Manipulation efficiency and the logic required to maintain pricing integrity (base price + modifiers - discounts) using pure JavaScript event listeners.
- Event-Driven Architecture: Utilization of click listeners to trigger state updates for Memory, Storage, and Delivery options.
- Defensive Programming: Ensuring promo codes are validated rigidly (e.g., matching "stevekaku") to prevent client-side exploitation.
- Semantic Layout: Structuring the application with accessibility in mind using semantic HTML5 tags and Bootstrap classes.
The application follows a simple Model-View-Controller (MVC) pattern implemented in a single file structure:
- Model: The internal variables tracking
memoryCost,storageCost,deliveryCost. - View: The HTML table updating dynamically via
innerText. - Controller: The
main.jsscript handling logic and bridging the Model and View.
| Component | Feature Description |
|---|---|
| Product Customizer | Toggle between 8GB/16GB Ram, 256GB/512GB/1TB Storage |
| Real-time Totals | Immediate recalculation of the "Total Price" upon any selection |
| Promo Code System | Application of a 20% discount code with validation |
| Delivery Options | Tiered pricing for standard vs. prime delivery |
- State Persistence: Implement
localStorageto save user selections on page reload. - Componentization: Refactor the vanilla JS into Web Components for reusability.
- Server-Side Validation: (Hypothetical) Move pricing logic to a Node.js backend to prevent client-side tampering.
- Unit Testing: Add Jest tests for the calculation logic functions.
- A modern web browser (Chrome, Firefox, Edge).
-
Clone the Repository
git clone https://github.com/sajidmahamud835/shopping-cost-calculator-js.git cd shopping-cost-calculator-js -
Run Application
- Simply open
index.htmlin your browser. - OR use a live server extension in VS Code.
- Simply open
Explore other components of the research portfolio:
- EasyCom - The evolution of this concept into a full-scale E-commerce application.
- InspectHealth - Another example of frontend-focused development using libraries (React).
- BankSync - Shows how financial calculations (like in this calculator) are handled securely in a real app.
Distributed under the MIT License. See LICENSE for more information.