Skip to content

Commit

Permalink
Make testcases for all lessons #10 working!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Mar 7, 2024
1 parent 5b4fa2a commit f7d87b6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion courses/objects/accessing-nested-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ console.log(ourStorage.desk.drawer);
`OurStorage.desk.drawer` هو سلسلة `stapler`.

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
قم بكتابة الكود الذي يقوم بطباعة السرعة القصوى للطائرة فقط!!!
</div>
14 changes: 14 additions & 0 deletions precodes/objects/accessing-nested-objects.js
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'],
}
41 changes: 41 additions & 0 deletions testcases/objects/accessing-nested-objects.js
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 = "حاول مرة أخرى";
}
2 changes: 1 addition & 1 deletion testcases/objects/manipulating-complex-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ if (!code.includes('october-73')) {
msg = "هل قمت بتعديل القيمة الصحيحة؟";
}

}
}

0 comments on commit f7d87b6

Please sign in to comment.