javascript - How do I calculate an JavaScript expression called inside a string?

132 views Asked by At

I am creating a simple calculator in HTML and I've created an input field. You can type there an sum and it must be calculated. Only, I don't know how...
Example:
I have a string:

234-231*Math.sqrt(9)

Is there a way to calculate this sum inside the string using javascript?

1

There are 1 answers

1
Ahs N On

Use the eval() function. Like so: eval("234-231*sqrt(9)");