-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
e9cf75f
commit eb15964
Showing
5 changed files
with
56 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
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,9 @@ | ||
const fighter = { | ||
name: 'Mig 29', | ||
country: 'Egypt', | ||
speed: 2.25, | ||
speedUnit: 'Mach', | ||
maxAltitude: 65000, | ||
maxAltitudeUnit: 'ft', | ||
operator: 'Egyptian Air Force', | ||
} |
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 | ||
} catch (error) { | ||
return `${error}`; | ||
} | ||
} | ||
if (code.includes("while")) { | ||
const output = handleCodeRun(code); | ||
console.log(output); | ||
if (JSON.stringify(output) === JSON.stringify([ '1', '2', '3', '4', '5' ])) { | ||
isPass = true; | ||
} else { | ||
isPass = false; | ||
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار."; | ||
} | ||
} 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// the code must contain this line console.log(fighter.hasOwnProperty("speed")) | ||
const regex = /console.log\((\w+)\.hasOwnProperty\("(\w+)"\)\)/; | ||
if (regex.test(code)) { | ||
isPass = true; | ||
} else { | ||
isPass = false; | ||
msg = "قم بالتأكد من استخدام الدالة hasOwnProperty() للتأكد من وجود الخاصية في الكائن المعطى." | ||
} |