Skip to content

Commit

Permalink
Add introduction to loops and example code and make quiz on intro/array
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Feb 7, 2024
1 parent 03c273a commit 7728a4f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions courses/arrays/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,42 @@ Array[0] = 15;
```

لدينا الآن قيمة المصفوفة `[30, 40, 15]`.

# الحلقات - Loops

الحلقات هي بنيات أساسية في جافا سكريبت تمكنك من تكرار الأوامر بشكل متكرر. مثلا تكرار طباعة الأرقام من 1 إلى 10.

## مثال:
```js
for (let i = 1; i <= 10; i++) {
console.log(i);
}
```
النتيجة ستكون:

```js
1
2
3
4
5
6
7
8
9
10
```

# إستخدام الحلقات مع المصفوفات

يمكنك استخدام الحلقات للوصول إلى كل عنصر في المصفوفة. مثلا:

```js
const animals = ['lion', 'tiger', 'cheetah', 'leopard', 'jaguar'];
for (let i = 0; i < animals.length; i++) {
console.log(animals[i]);
}
```
<div class="quiz">
قم بطباعة كل رقم مضاف عليه 10 في المصفوفة <code>numbers</code> باستخدام الحلقة <code>for</code><br>
</div>
9 changes: 9 additions & 0 deletions precodes/arrays/intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
output:
19
12
13
14
15
*/
const numbers = [9, 2, 3, 4, 5];
30 changes: 30 additions & 0 deletions testcases/arrays/intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// check if output is = [19, 12, 13, 14, 15];
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 === "19\n12\n13\n14\n15") {
isPass = true;
msg = "Pass";
}

0 comments on commit 7728a4f

Please sign in to comment.