If someone wants to check it out, I'm open to feedback and suggestions:
here is the code I used in the template.
let SEPARATOR = "##";
let code= "{{ QUESTION.globalextra | e('js')}}";//read code with gaps from the globalextra field
let field_values = {{ STUDENT_ANSWER}}; //read the student's answers
const regex = /\{\[.*?\]\}/;//reges to match the {[___]} GAP
for (let field of field_values) {//for each of the student's answer fill the GAP with the value
code = code.replace(regex, field);
}
let tests = {{ TESTCASES | json_encode }};
for (let test of tests) {//for each test add the test code to be executed BEFORE the actual code.
let testcode = test['testcode'];
let finalcode=testcode+"\n"+ code;
eval(finalcode); //code execution
}
@17943918#@>