-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change quiz in strings/intro, Tests that need adjustments #33
- Loading branch information
1 parent
7c8acd2
commit 76161de
Showing
2 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |