calculator

Website Link - https://macdonald91.github.io/calculator/

Advanced Web Calculator

This project is a more advanced web calculator integrated into a martial arts dojo website template. It includes features for basic arithmetic operations, square, percentage, plus/minus, decimal input control, and basic error handling (division by zero). It also maintains a simple history of operations.

Overview

The calculator is embedded within the <main> section of the HTML page. It utilizes a <table> for its layout and includes:

How to Use

  1. Save the files: Ensure you have index.html, the css folder (containing style.css and calculator.css), the scripts folder (containing calculator.js), and the media folder (containing logo.png) in the correct relative paths.
  2. Open in a browser: Open the index.html file in your web browser.
  3. Navigate to the Calculator: The calculator is located within the <main> section of the home page.
  4. Perform calculations:
    • Click the digit buttons to enter numbers.
    • Click the operator buttons (÷, ×, –, +) to select an operation.
    • Click the “.” button to enter decimal points (multiple decimal points are prevented).
    • Click the “=” button to see the result.
    • Click the “ac” button to clear the display and reset the calculator.
    • Click the “x²” button to square the current number.
    • Click the “%” button to calculate the percentage of the current number.
    • Click the “±” button to toggle the sign of the current number.

Project Files

Troubles and Challenges Faced

Integrating this calculator into the existing website template presented a few interesting challenges, and our previous conversations were instrumental in resolving some of them:

Through the iterative process of writing the code, testing it in the browser, and debugging. I was able to address these challenges and build a functional web calculator integrated into the website template. The use of hidden inputs for state management and the careful handling of user input and operations were the most significant learning points.