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. · לחץ על הרץ כדי לראות את התוצא כאן.