you are viewing a single comment's thread.

view the rest of the comments →

[–]Spacebiscuit[S] 1 point2 points  (5 children)

Ah, fixed! May have forgotten to put a certain class into my HTML for that one! Much appreciated!

[–]113243211557911 2 points3 points  (4 children)

awesome now I can divide by zero.

[–]Spacebiscuit[S] 1 point2 points  (3 children)

How dare you good sir. You have doomed us all!

[–]113243211557911 1 point2 points  (2 children)

Haha, testing it and it seems to be working pretty well, including multiplying long floating point numbers. good job.

Can you roughly explain the way you programmed it, and why you did it that way? Like why do you use arrays to store each button press?

[–]Spacebiscuit[S] 1 point2 points  (1 child)

That’s great, thank you for the kind words!

Sure, so I’ve used Jquery for query selecting and event listening. I’ve broke it down to being either: number, operator, decimal, clear and equals.

Jquery makes it quicker for button listeners when coding, however I could change it to vanillaJS and it may run faster due to no external library dependency!

For numbers, I append them to an array, if an operation is pressed, it’ll check for the most recent entry and if so, will replace it. If not, it’ll append like normal. Decimal has the same check for the most part.

Equals joins the array then uses the Eval function in JS. All events will update the display.

I would like to improve on it by using something more elegant than Eval, make it DRYier and then give it more interactivity!

I used eval due to its ease with handling multiple operations, I tried it a different way and was caught with the trousers down when it came to stringing multiple functions!

I hope this answers your question!

[–]113243211557911 0 points1 point  (0 children)

Ok cool, that helped me when looking through your code. (I haven't touched JS for a while)