Skip to content

Commit

Permalink
Add new quiz Make testcases for all lessons #10
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Mar 6, 2024
1 parent 0d1d35b commit 5b4fa2a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion courses/objects/manipulating-complex-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ const ourMusic = [
</mark>

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
قم بتغير العنصر <code>wars</code> من الكائن <code>fighter</code> و قم بإضافة حرب أكتوبر <code>october-73</code> إلى المصفوفة.
</div>
15 changes: 15 additions & 0 deletions precodes/objects/manipulating-complex-objects.js
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 : []
}
44 changes: 44 additions & 0 deletions testcases/objects/manipulating-complex-objects.js
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 = "هل قمت بتعديل القيمة الصحيحة؟";
}

}

0 comments on commit 5b4fa2a

Please sign in to comment.