I am trying to convert a string with included operations (e.g. addition, subtraction, etc.) to a number in JavaScript. For example, if i have the string "12+5-8", it should output the number (not string) 20. I literally cannot find an answer anywhere and I am open to sugestions.
function equals() {
text = document.getElementById('result').innerHTML;
document.getElementById('result').innerHTML = text; //returns same string with operators + - etc. (original)
}
The innerHTML of the element with the id "result" can be any form of operation (e.g. "158/2 + 12" or "1/1/23").
If you guys need any more information I will gladly help.
Thanks again.