Chapter 3: Variables
الشابتر ٣: المتغيرات
1. What is a variable?١. يعني إيه متغير؟
A variable is a box with a name. It stores a value and the value can change. Think of a bucket of fish: it starts at 0, you add 3, then 7, now it has 10.المتغير صندوق له اسم، بنخزن فيه قيمة والقيمة بتتغير. تخيّل جردل سمك: بيبدأ صفر، تحط 3، وبعدين 7، يبقى فيه 10.
2. Declare, assign, reassign٢. إعلان وتعيين وتغيير
let creates the box. = stores the value on the right in the box on the left. fish = fish + 3 takes what is in the box, adds 3 and stores it back.let بتعمل الصندوق. = بتخزن القيمة اللي على اليمين في الصندوق. fish = fish + 3 يعني خد اللي في الصندوق وزوّد 3 وخزّنه تاني.
let fish; fish = 0; fish = fish + 3; fish = fish + 7; console.log(fish);
10
Careful: here = means "store", not "equals" like in math.خد بالك: علامة = هنا معناها "خزّن" مش "يساوي".
3. Print a variable: no quotes٣. طباعة المتغير: من غير تنصيص
Without quotes it prints the value. With quotes it prints the word.من غير تنصيص بيطبع القيمة. بتنصيص بيطبع الكلمة نفسها.
let fish;
fish = 10;
console.log(fish);
console.log("fish");10 fish
4. The first value can be any number٤. أول قيمة ممكن تبقى أي رقم
Start with 700, add 1500: you get 2200.ابدأ بـ 700 وزوّد 1500 يبقى 2200.
let allowance; allowance = 700; allowance = allowance + 1500; console.log(allowance);
2200