-
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.
Make testcases for all lessons #10 working!!!
- Loading branch information
1 parent
5b4fa2a
commit f7d87b6
Showing
4 changed files
with
57 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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'], | ||
} |
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,41 @@ | ||
/** | ||
* 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}`; | ||
} | ||
} | ||
const output = handleCodeRun(code) | ||
if (output == "1500") { | ||
if (code.includes("console.log(1500)" || 'console.log("1500")' || "console.log('1500')")) { | ||
isPass = false; | ||
msg = "لا تحتال علينا, حاول مرة أخرى"; | ||
} else { | ||
isPass = true; | ||
} | ||
} else { | ||
isPass = false; | ||
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 |
---|---|---|
|
@@ -41,4 +41,4 @@ if (!code.includes('october-73')) { | |
msg = "هل قمت بتعديل القيمة الصحيحة؟"; | ||
} | ||
|
||
} | ||
} |