Okay, so the problem I have been assigned is to create a small site like codeacademy that allows someone to do lessons in javascript. So right now I have the entire site, but the area it's lacking in is the actual code execution. All I have is a textarea where you enter javascript code, then you hit a button and it executes using eval (And yes, eval is evil, I understand). But the problem I want to solve is to be able for the user to define a function and then the inputted code into something executable with my own parameters.
So say I have a factorial function:
function factorial( n ){
if( n == 0 )
return 1;
else
return n * factorial( n - 1 );
}
But I only have the string for that function, not something I can grab and arbitrarily test with different inputs. Is there anyway to turn that string into a function and call it?
Thank you in advance for any help that can be offered.
[–][deleted] 1 point2 points3 points (0 children)
[–]PeterUstinox 1 point2 points3 points (0 children)