-
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.
Add new quiz Make testcases for all lessons #10
- Loading branch information
1 parent
0d1d35b
commit 5b4fa2a
Showing
3 changed files
with
60 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const fighter = { | ||
name: 'Mig 29', | ||
country: 'Egypt', | ||
speed: { | ||
maxSpeed: 1500, | ||
maxSpeedUnit: 'km/h', | ||
minSpeed: 400, | ||
minSpeedUnit: 'km/h', | ||
}, | ||
maxAltitude: 65000, | ||
maxAltitudeUnit: 'ft', | ||
operator: 'Egyptian Air Force', | ||
weapons: ['Missiles', 'Bombs', 'Guns'], | ||
wars : [] | ||
} |
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,44 @@ | ||
/** | ||
* 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.join("\n"); | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
if (!code.includes('october-73')) { | ||
isPass = false; | ||
msg = "هل قمت بتعديل القيمة الصحيحة؟"; | ||
} else { | ||
const output = handleCodeRun(code + "\nconsole.log(fighter.wars[0]);") | ||
console.log(output); | ||
if (output.includes("october-73")) { | ||
isPass = true; | ||
msg = "احسنت"; | ||
} else { | ||
isPass = false; | ||
msg = "هل قمت بتعديل القيمة الصحيحة؟"; | ||
} | ||
|
||
} |