I currently develop a tutorial site for the basics of web development (HTML, CSS, and JavaScript, for beginners) I am doing I need a setup where I can provide in-depth coverage of all types of topics and then provide a basic sandbox environment where the user can write the code which resolves the question asked at the end of each tutorial section.
Is this a correct example in which to use dynamic function creation would be considered a good idea? Let's look at an example.
& lt; Script & gt; Function check () {eval ('var f =' + document.getElementById ('user_code'). Value); If (f (5, 10) == 50) {// user correctly write a function that returns the product of its parameter to back}} & lt; / Script & gt;
Is this all bad idea? If so, please explain.
It looks as if it could work However, the biggest challenge in your environment can be error management is. Students will definitely make all kinds of errors:
- Collect timing errors, which should be run in
eval ()
In a more detailed approach, parsed javascript can be parsed by a parsed tree, such as an endless loop or stack overflow;
Represent it, then compare it with an expected purse tree. If this does not match, then tell what is wrong and students are trying again. If it matches, you can eval ()
and call the function, knowing that it will do as you wish.
Javascript is a challenging but definitely not impossible to implement a laser and parser for JavaScript.
Comments
Post a Comment