+ 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?
6 Réponses
0
I finally did it actually.
https://chidicalc.netlify.app
+ 6
JS Coder What library is recommended and how do I parse an expression without eval.
+ 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.
+ 5
JS Coder Thanks a lot. Will do just that.
+ 3
Do not use jQuery in 2019.
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.