0

   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.

  • 1
    Is this an assignment? If it is, for what type of class? The answer will probably determine how you’re supposed to solve this. – Ry- Apr 28 '18 at 18:42
  • It is not for any assignment. It's just that i was playing with the idea and hit this wall. – Daniel Iova Apr 28 '18 at 18:51

0 Answers0