-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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.join("\n"); | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
|
||
const output = handleCodeRun(code) | ||
if (output == "1500") { | ||
if (code.includes("console.log(1500)" || 'console.log("1500")' || "console.log('1500')")) { | ||
msg = "لا تحتال علينا, حاول مرة أخرى"; | ||
} else { | ||
isPass = true; | ||
} | ||
} else { | ||
msg = "حاول مرة أخرى"; | ||
} |
8 changes: 8 additions & 0 deletions
8
testcases/objects/accessing-object-properties-with-variables.js
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// the code must contain console.log(fighter[Country]) | ||
const codeRegex = /console.log\(fighter\[Country\]\)/; | ||
|
||
if (codeRegex.test(code)) { | ||
isPass = true; | ||
} else { | ||
msg = "تاكد من الشروط"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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.join("\n"); | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
|
||
const output = handleCodeRun(code); | ||
// TODO: make the quiz uncheatable by checking the the code logic | ||
if (output == "19812") { | ||
isPass = true; | ||
} else { | ||
msg = "الناتج خطاء" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if (code.includes("delete") && code.includes("operator") && code.includes("fighter")) { | ||
isPass = true; | ||
} else { | ||
msg = "الله يبارك فيك ركز شوية وحاول مره ثانية" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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.join("\n"); | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
|
||
if (!code.includes('october-73')) { | ||
msg = "هل قمت بتعديل القيمة الصحيحة؟"; | ||
} else { | ||
const output = handleCodeRun(code + "\nconsole.log(fighter.wars[0]);") | ||
console.log(output); | ||
if (output.includes("october-73")) { | ||
isPass = true; | ||
} else { | ||
msg = "هل قمت بتعديل القيمة الصحيحة؟"; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const regex = /console.log\((\w+)\.hasOwnProperty\("(speed)"\)\)/; | ||
|
||
if (regex.test(code)) { | ||
isPass = true; | ||
} else { | ||
msg = "قم بالتأكد من استخدام الدالة hasOwnProperty() للتأكد من وجود الخاصية في الكائن المعطى." | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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.join("\n"); | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
|
||
code += "\nconsole.log(fighter.speed+fighter.speedUnit)" | ||
const output = handleCodeRun(code); | ||
const expectedOutput = "2450"; | ||
if (output.includes(expectedOutput)) { | ||
isPass = true; | ||
} else { | ||
msg = "الله يبارك فيك ركز شوية وحاول مره ثانية" | ||
} |