Calculator
On freecodecamp I am now doing project since well I completed the algorithms and in this project I am supposed to fullfill the user stories below. User Story: I can add, subtract, multiply and divide two numbers. User Story: I can clear the input field with a clear button. User Story: I can keep chaining mathematical operations together until I hit the equal button, and the calculator will tell me the correct output.
How I solved the problem
On script I had functions for all the operators, numbers and for the screen, using their ids. What the function does it gets the element by id in the html page there for I wrote a plus equal sing so that they can append everytime when a button is clicked meaning the button can be clicked as many time. I had another function called the equal function which I used a different way to call that function which was using the word eval. Eval is a function which evaluates a string as though it were an expression and returns a result.
On the body I had buttons which will work for my calculator and made it to be onclick, which means they will be clickble. I created a text area using textarea for the screen to show numbers. I also created buttons for my operators to be onclick. I gave all my buttons ids so that when I call them on a function I cal them using their ids and also to adhere to what I am telling the function.
Lastly I styled my calculator using margins and colors to make it look pretty, I also used paddings, width and the border radius to make it look a bit round. I decide not to add to much color but only on operators and AC button which is the clearing button.
Conclusion
I enjoyed making this project because I thought it was going to be that hard and it wasn’t. It was good that I got do it as sometings it I forgot but I managed to do it. I also got to understand more about eval because I had forgotten about it. It was an absolete fun project to do and looking forward to the next one.