Skip to content

daniyalmaster693/Calculator-App

Repository files navigation

Calculator-App

A calculator app made using HTML, CSS, and Javascript. This is the solution to the Odin Project's calculator task

Design Followed

The design used for this calculator was a community made design from Figma.

  • Link to design: https://www.figma.com/community/file/1041082497681424521/responsive-calculator-app
  • Outcome

    The image of the solution to the challenge

    Links

  • Link to task: https://www.theodinproject.com/lessons/foundations-calculator#assignment
  • Link to live demo: https://daniyalmaster693-calculator-app.vercel.app
  • What have I learned

  • I've improved my understanding of handling multiple user inputs using Javascript
  • I've learned how to handle and use keyboard input
  • I've learned how to add sound effects to a project
  • I've learned how to copy something to a user's clipboard
  • I've learned how to create a dark and light mode toggle
  • I've learned how to automatically detect and set a theme based on a user's preferences
  • Keyboard Controls

  • Key "Enter": Calculate Answer
  • Key "Backspace": Delete Digit
  • Key "c": Clear Calculator
  • Key "+": Add
  • Key "-": Subtract
  • Key "x": Multiply
  • Key "/": Divide
  • Key ".": Decimal
  • Keys "0-9": Numbers
  • How did I complete this project?

    I started by creating my HTML elements and assigning classes. Next, I moved onto the CSS, where I imported my fonts, and began with things like removing default properties, and using flexbox to center the calculator. I spent some time adding background colors, font colors, font properties, hover effects, and small details such as changing the cursor to pointer when hovering over a button. Then, I began working on the Js. I started my ensuring the dom was loaded in, to ensure event listeners would work. I declared the nesscary variables for buttons and things needed. I created my changeDisplayMode() function to switch the theme from light to dark mode. I spent time utilizing things like adding and removing class lists, to change hover effects, font and background colors. In addition, I learned how to set a viewing theme based on the user's preference. Next, I worked on creating a system for displaying button inputs. I created a function called updateCalDisplay (). I used things like text content, which allowed me to display the content of the html element when a button is clicked. This allowed me to do things like click a button and have it's value show up on the display. I also, created a limit for the amount of digits allowed on the display. I used an if statement to define the logic of what to do if the digits are 13, and if their less then 13. Now, I had some basic features of my calculator working. I moved onto some smaller functions such as deleting digits, and clearing the calulator. I once again used an if statement to define the logic of what to do if there is no digit in the display, and if there is a digit. For the clearCal() function, I reset all the values of the calculator to the orignal, before anything was changed. Now, once this was done, I created my system to perform calculations. I created a function to handle displaying pi and the exponent, as well as the value of the first number. Then in my calculate() function, I used a switch instance to define the logic of how to perform every operation. I used built in Javascript functions such as parseFloat() to convert a strings into numbers, and toFixed() to define how many decimals to show. I added some final touches such as audio that plays when you click or type a button, as well as keyboard input, to allow ease of use. Finally, I spent some time testing everything, tested the website on multiple browsers and used the bulit in device emulation feature to view how the calculator would look on different displays.

    About

    A calculator app made using HTML, CSS, and Javascript. The app uses a clean and simple UI, and performs arithmetic operations.

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published