Happy New Year!
The user stories I had to fufill to complete the challenge:
- Add, subtract, multipy and divide two numbers.
- Clear the input field with a clear button.
- Chain mathematical operations together until hitting the equal button, and still get the correct output.
I realized from working on my Pomodoro clock that I sometimes get caught up with “making it pretty” that I was losing focus on making it work. So, once I created my basic buttons and display, I left the styling bare to finish later. I feel like this worked to my advantage in keeping me focused on one task at a time.
When it came to making my buttons functional, I knew that I would need to store the keys being clicked by the user as well as make them display on the screen. It actually didn’t take long for me to get that part working. The hard part was really getting the calculator to evaluate the input. I started off trying to use methods to take in the input as one long string, converting it to integers and operators, then evaluating them. I was spinning my wheels for a bit.
After consulting the Google gods, I discovered that there is actually a method called ‘eval’ that can simply evaluate a string as an equation. Bingo! So far, I haven’t been able to break it and I haven’t gotten word that anyone else has broken it yet. Sounds like a success to me!
I used Palleton to find a triad of pastel colors and a couple Google Fonts to give my calculator some life.