Updated:

I learned jQuery today! ✌

  • Read w3school document about jQuery and made notes
  • Created a project using jQuery (a simple calculator!)

Here is my calculator!

calculator

The calculator handles long sequence of calculation via reusing four global variables, num1, num2, operator, and total.

When the second operator is added to the sequence, the existing expression is calculated and saved in num1. For example, if + is clicked after 1+2, the value of 1+2 is saved in num1 so the user can continue their calculation. The screen display would be showing 3+, and the calculator will be waiting for the input to save in num2.

Some edge cases were considered too:

  • When there is a decimal point in the value, you cannot add another one.
  • When an operator is clicked after another operator, the old one is discarded.
  • When you click the equal button after an operator, the action is ignored.

Next up:

  • Fix the bug that causes Uncaught TypeError When you click the equal button with an input of only one number (make the result equal to the given number)
  • Look into Node.js when I’m confident enough with jQuery!

Tags:

Categories:

Updated:

Leave a comment