I’m trying to make a Javascript function that will take a mathematical expression and apply it to a predefined number, for example:
var myNum = 10;
function EQ(eq){
// code here
}
For example the input should me something like this:
EQ("*100/10"); //output 100
EQ("+100"); //output will be 110
EQ("-+=1"); //output false
Is there any way to do that?
Thanks
You could probably work
eval()into a simple solution. For instance:I’d encourage you to expand upon this by implementing a
try-catchand handling exceptions.