Numbers and maths · الأرقام والرياضيات
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · تحتاج هذه الصفحة إلى متصفح حديث (يدعم SharedArrayBuffer). يرجى تحديث Chrome أو Edge أو Firefox أو Safari إلى أحدث إصدار.
English
Maths like a calculator
- JavaScript does maths with
+-*/. - There is only one kind of number, so
/can give a decimal:7 / 2is3.5.
العربية
رياضيات الآلة الحاسبة
- JavaScript يقوم بالحسابات الرياضية باستخدام
+-*/. - يوجد نوع واحد فقط من الأرقام، لذا يمكن لـ
/أن يعطي عشرياً:7 / 2هو3.5.
console.log(7 + 2); // → 9
console.log(7 / 2); // → 3.5
English
Remainder and powers
%gives the remainder after dividing:23 % 5is3(5 goes in 4 times, 3 left over).**raises to a power:2 ** 5is2 × 2 × 2 × 2 × 2.
العربية
الباقي والأسس
%يعطي الباقي بعد القسمة:23 % 5هو3(5 يدخل في 4 مرات، ويتبقى 3).**يرفع إلى أس:2 ** 5هو2 × 2 × 2 × 2 × 2.
console.log(23 % 5); // → 3
console.log(2 ** 5); // → 32
English
Order of operations
*/%happen before+and-— the same rules as in maths class.- Use brackets
( )to force what should happen first.
العربية
ترتيب العمليات
*/%تحدث قبل+و-— نفس قواعد الرياضيات في الفصل.- استخدم الأقواس
( )لإجبار ما يجب أن يحدث أولاً.
Explore · استكشف
Order of operations, step by step · ترتيب العمليات، خطوة بخطوة
× and ÷ happen before + and −. Brackets go first of all. · × و ÷ يحدثان قبل + و −. الأقواس تأتي أولاً.
console.log(2 + 3 * 4); // → 14 (the 3 * 4 first)
console.log((2 + 3) * 4); // → 20 (the brackets first)
English
Common mistakes
%is the remainder operator;/can give a decimal."3" + 4gives"34"(a string), not7.
العربية
أخطاء شائعة
%هو عامل الباقي؛/يمكن أن يعطي عشرياً."3" + 4يعطي"34"(سلسلة نصية)، وليس7.
English
Now you try
- Use the maths operators.
- Press Check answer to test it.
العربية
الآن جرب بنفسك
- استخدم عوامل الرياضيات.
- اضغط على تحقق من الإجابة لاختبارها.
Log 6 times 7 (it is 42). · سجل 6 ضرب 7 (قيمته هي 42).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Use % to log the remainder when 23 is divided by 5 (it is 3). · استخدم % لأخرج الباقي عند قسمة 23 على 5 (وهو 3).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
a is 4 and b is 8. Log their average, (a + b) / 2 (it is 6). Use brackets so the addition happens first. · a هي 4 و b هي 8. أخرج متوسطهما، (a + b) / 2 (وهي 6). استخدم الأقواس بحيث تتم الإضافة أولاً.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.