I have a counting-Discord bot which works perfectly fine, but i want to add some specials. Users should can use mathematical expressions like +;-;/;*, but i can’t get the result of the string
example:
console.log(+"14+2") or console.log(Number.parseInt(+"1+3*5-1"))
all equals NaN or just the first number.
i just found on another stackoverflow question how i can if it’s a number like true and false, but not the result.
>Solution :
You could just use math.js:
console.log(math.evaluate("14+2"))
console.log(math.evaluate("1+3*5-1"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.0.1/math.js"></script>