Hello everybody,
I have a table that's thousands of lines long, with a column called "Formula" which contains small string expressions like:
amount = salary * 0.11;
What I'm trying to do is run this string in my code, so that it updates the `amount` variable based on which line I select. However, I am running into an error when I try to run the string as code.
This is my code, which is able to compile with the correct answer in other online compilers. However, when I run this in my automation script (specifically the line where I call `func()`) I receive TypeError: func is not a function.
let code = "amount = salary * 0.11;";
// Define the function with the desired arguments
let func = new Function('salary', code);
// Call the function with the desired argument values
func(50000);
console.log(amount);
I've tried using `eval()` to run this (I know it is not best practice) but similarly received the error ReferenceError: eval is not defined.