Skip to content

Commit

Permalink
change quiz in strings/intro, Tests that need adjustments #33
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Mar 3, 2024
1 parent 7c8acd2 commit 76161de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
5 changes: 4 additions & 1 deletion courses/strings/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@ World;
```

<div class="quiz">
قم بأنشاء متغير يحتوي على قيمه سلسله اسمك
قم بإنشاء متغير و إستخدم تسلسلات التخطي لطباعة النص التالي على وحدة التحكم <br>
<code>Ich Bin Yazan</code><br>
<code> am Yazan</code><br>
يجب أن تكون في أسطر مختلفة
</div>
45 changes: 39 additions & 6 deletions testcases/strings/intro.js
Original file line number Diff line number Diff line change
@@ -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";
}

0 comments on commit 76161de

Please sign in to comment.