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.
日本語
あなたも試してみよう
- 数学演算子を使用します。
- Check answer を押して確認する。
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. · 実行ボタンをクリックして出力を確認してください。