Skip to content

The project is a simple browser calculator implemented in JavaScript, which allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and exponentiation. The calculator also keeps a history of all operations performed, which can be displayed to the user.

Notifications You must be signed in to change notification settings

code-mike-code/browser-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser Calculator

See the live version of Browser Calculator project.

Project made during learning process with my mentor program devmentor.pl. The project is a simple browser calculator implemented in JavaScript, which allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and exponentiation. The calculator also keeps a history of all operations performed, which can be displayed to the user. The program prompts the user for input, validates the operations, and handles errors such as division by zero or invalid inputs. The main functionalities include performing calculations, storing operation history, and providing user feedback.

Refactoring

During the refactoring process, the code was optimized to improve readability and reduce redundancy. The main changes included:

Replacing multiple if-else statements with a dictionary (operations): This allowed for a more concise and maintainable way to map operations to their corresponding methods.

Binding methods to the Calculator instance: This ensured that the correct context (this) was maintained when calling the methods from the operations dictionary.

Simplifying the user input validation: The code now directly checks if the action is valid and if the inputs are numbers, reducing the complexity of the logic.

 

💡 Technologies

HTML5 JavaScript

 

🔗 See also

Are you interested in SCSS and JavaScript? See my other project Landing Page MGUU.

 

💿 Installation

No Required

 

💭 Conclusions for future projects

The refactoring made the code more modular and easier to extend. In the future, additional operations could be added by simply extending the operations dictionary and adding corresponding methods to the Calculator class. Furthermore, the code could be further improved by adding more robust error handling and possibly a user interface for a better user experience.

 

🙋‍♂️ Feel free to Reach Out!

If you have questions, ideas, or just want to chat about code (or the meaning of life), don’t hesitate to contact me. Open an issue, drop me a pull request, or send a message—carrier pigeon works too, but GitHub might be faster. Let’s build something awesome together! 🚀

 

👏 Thanks / Special thanks / Credits

Thanks to my Mentor - devmentor.pl – for providing me with this task and for code review.

About

The project is a simple browser calculator implemented in JavaScript, which allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and exponentiation. The calculator also keeps a history of all operations performed, which can be displayed to the user.

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •