Best ways to implement a flawless basic calculator with HTML, css and jQuery(JavaScript). | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Best ways to implement a flawless basic calculator with HTML, css and jQuery(JavaScript).

I've been working on this lately. It seems this seemingly simple task is not as easy as it seems. Does anyone have tips or work done?

26th Jun 2019, 7:04 PM
Toby Chidi
Toby Chidi - avatar
6 Answers
0
I finally did it actually. https://chidicalc.netlify.app
28th Apr 2021, 9:07 AM
Toby Chidi
Toby Chidi - avatar
+ 6
JS Coder What library is recommended and how do I parse an expression without eval.
1st Jul 2019, 12:35 PM
Toby Chidi
Toby Chidi - avatar
+ 5
There are a lot of calculators I've seen on sololearn that use the javascript eval function. If you want simple expression parsing, that is an easy way to go, but I would NOT recommend it. Eval is not good for security, and by writing something on your own to parse an expression, you will learn much more. I'm not really sure what other tips to give, but if you have a more specific question about it, I can probably help. Also Andrea Proone (ilmito106) I wouldn't use jquery either, but if someone wants to use the library, there's nothing wrong with that.
28th Jun 2019, 2:06 AM
JS Coder
+ 5
JS Coder Thanks a lot. Will do just that.
2nd Jul 2019, 6:35 PM
Toby Chidi
Toby Chidi - avatar
+ 3
Do not use jQuery in 2019.
27th Jun 2019, 6:06 PM
Andrea Proone (ilmito106)
Andrea Proone (ilmito106) - avatar
0
Toby Chidi To parse it without a library will require you to do some research about parsers. You could do it like a more formal parser (like what a programming languahe would do), or you could look up regular expressions. Either of those would teach you more, but there are also libraries that do safe math parsing. The main one I've seen is mathjs. It has a math eval function that takes in a math expression with error handling and safely calculates the answer.
1st Jul 2019, 5:20 PM
JS Coder