diff --git a/courses/strings/intro.md b/courses/strings/intro.md index fff3245..779e535 100644 --- a/courses/strings/intro.md +++ b/courses/strings/intro.md @@ -83,5 +83,8 @@ World; ```
-قم بأنشاء متغير يحتوي على قيمه سلسله اسمك +قم بإنشاء متغير و إستخدم تسلسلات التخطي لطباعة النص التالي على وحدة التحكم
+Ich Bin Yazan
+ am Yazan
+يجب أن تكون في أسطر مختلفة
diff --git a/testcases/strings/intro.js b/testcases/strings/intro.js index 4eac26d..e78fe0d 100644 --- a/testcases/strings/intro.js +++ b/testcases/strings/intro.js @@ -1,9 +1,42 @@ -// create regex check if the code contains var or cost or let varibale that contain A string -const regex = /(var|let|const)\s*[a-zA-Z0-9]*\s*=\s*("|'|`)[a-zA-Z0-9]*\2(;|)/ -if (regex.test(code)) { +/** + * Executes the provided code and captures the output of console.log. + * @param {string} code - The code to be executed. + * @returns {string} - The captured output of console.log. + */ +function handleCodeRun(code) { + try { + const capturedOutput = []; + const originalConsoleLog = console.log; + console.log = (...args) => { + capturedOutput.push( + args.map((arg) => { + if (typeof arg === "object" && arg !== null) { + return JSON.stringify(arg); + } + return arg.toString(); + }).join(" "), + ); + originalConsoleLog(...args); + }; + if (code) { + eval(code); + } + console.log = originalConsoleLog; + return capturedOutput + } catch (error) { + return `${error}`; + } +} + +const output = handleCodeRun(code); +// const regex = /(let|const|var)\s+\w+\s*=\s*('|`|')\w+(`|'|")/; +// if (regex.test(code)) { +// console.log("You have declared a variable with a string value"); +// } + +if (output == "Ich Bin Yazan\nI am Yazan") { isPass = true; - msg = 'Good job!'; } else { - isPass = false; - msg = "تحقق من الشروط المطلوبة" + isPass = false; + msg = "The output is not correct"; } \ No newline at end of file