Lesson 1 / الدرس 1
What a program is / ما هو البرنامج
Before any syntax: a program is a list of instructions, followed exactly, in order, by something that understands nothing. Most beginner difficulty comes from forgetting the last part.
قبل أي صيغة: البرنامج قائمة تعليمات تُتَّبع بالضبط بالترتيب من شيء لا يفهم شيئًا. ومعظم صعوبة المبتدئ تأتي من نسيان الجزء الأخير.
You already write programs. A recipe is one, and so are directions to your house. Both are a sequence of steps that produce a result if followed in order. The only thing that makes programming harder than writing directions is that the follower is a machine, and a machine will not fill in anything you left out.
Directions for a person:
1. Go to the second street and turn right.
The same, for a machine:
1. Walk forward.
2. Count every street you cross.
3. If the count is 2, stop.
4. Otherwise, go back to step 1.
5. Turn 90 degrees clockwise.
Three things every program does
| It can | Which means | Lessons |
|---|---|---|
| Remember | Put a value somewhere and get it back | 3 to 8 |
| Decide | Do one thing or another, based on a test | 9 to 11 |
| Repeat | Do something many times without writing it many times | 12 to 14 |
That is the whole of programming, at this level. Everything else — functions, arrays, objects, the entire JavaScript language — is a way of organising those three so that a large program stays understandable.
Why this course uses JavaScript
The logic in this course is the same in every language — Python, PHP, Java and JavaScript all have variables, conditions and loops, and they differ mostly in punctuation. JavaScript is used here for one practical reason: it is already in the browser you have open, so there is nothing to install, and the next course builds directly on it.
One habit is worth starting today. Before writing any code, write the steps in ordinary language — Arabic or English, whichever you think in — one line per step, as if instructing a very literal person. Most programs that will not work were never clear as a list of steps either, and finding that out on paper costs a minute instead of an hour.
2 + 2 واضغط Enter. وذلك السجل أسرع طريقة لاختبار فكرة واحدة، وستستخدمه باستمرار بقية هذه الدورة.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. What are the three things every program can do?
Everything else — functions, arrays, whole languages — is a way of organising those three so a large program stays understandable.
2. A program does something strange. What is almost always true?
This is not only an attitude — it is what makes debugging possible. A machine that follows rules can be traced; a capricious one cannot.
3. Why does this course use JavaScript rather than another language?
Variables, conditions and loops exist in every language and differ mostly in punctuation. What you learn here transfers.
Score / النتيجة: 0 / 3
Your task / مهمتك
Pick something you do without thinking — making tea, getting to work, logging in to a site — and write it twice on a page: once as you would tell a person, and once as you would have to tell a machine, with every assumption spelled out and every decision made explicit. Then mark the places where the second version had to make a decision the first one hid.
اختر شيئًا تفعله دون تفكير — إعداد الشاي أو الذهاب إلى العمل أو تسجيل الدخول إلى موقع — واكتبه مرتين في صفحة: مرة كما تخبر إنسانًا، ومرة كما ستضطر أن تخبر آلة، بكل افتراض مكتوب وكل قرار صريح. ثم علّم المواضع التي اضطرت فيها الصيغة الثانية إلى قرار أخفته الأولى.
- Both versions of the same everyday task صيغتان للمهمة اليومية نفسها
- The machine version numbered, one action per line صيغة الآلة مرقّمة، فعل واحد لكل سطر
- At least three hidden assumptions made explicit ثلاثة افتراضات خفية على الأقل صريحة
- At least one decision, and one repetition قرار واحد على الأقل وتكرار واحد