Skip to content

Commit

Permalink
Add new quiz hahahahahahahha
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Apr 7, 2024
1 parent 2728a86 commit 5ef9f77
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion courses/loops/iterate-through-an-array-with-a-for-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ for (let i = 0; i < arr.length; i++) {
وتنتهي الحلقة لأن شرط `i < arr.length` لم يعد صحيح.

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
قم بكتابة دالة تاخذ مصفوفة من الأرقام وتعيد مجموعها. يجب عليك أن لا تغير أسم الدالة.
</div>
4 changes: 4 additions & 0 deletions precodes/loops/iterate-through-an-array-with-a-for-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function SumArr(arr)
{
// write your code here :|
}
32 changes: 32 additions & 0 deletions testcases/loops/iterate-through-an-array-with-a-for-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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}`;
}
}
output = handleCodeRun(code+"\nconsole.log(SumArr([1, 2, 3, 4, 5]));");
const expectedOutput = "15";
if(output[output.length-1] == expectedOutput){
isPass = true;
} else {
isPass = false;
msg = "يرجى التأكد من أن الدالة تعمل بشكل صحيح";
}

0 comments on commit 5ef9f77

Please sign in to comment.