I'm getting some inputs from the user and saving them in a div tag just like a calculator works, for example, a user puts 100-50+30 then I store it in div tag at and when user clicks on go button I want to show him the result which is 80. I tried parseint and number since string contains operators like + / * these don't work
var a = document.querySelector(".output").innerHTML;
Use eval()
function
var expression = '100-50+30';
console.log(eval(expression));
The eval()
function evaluates JavaScript code represented as a string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval