mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-13 04:00:12 -04:00
chore(i18n,learn): processed translations (#50114)
This commit is contained in:
@@ -9,23 +9,25 @@ dashedName: generate-random-whole-numbers-with-javascript
|
||||
|
||||
# --description--
|
||||
|
||||
小数の乱数を生成できるのはとても便利ですが、それを利用して整数の乱数を生成すればさらに便利です。
|
||||
You can generate random decimal numbers with `Math.random()`, but sometimes you need to generate random whole numbers. The following process will give you a random whole number less than `20`:
|
||||
|
||||
<ol><li><code>Math.random()</code> を使用して小数の乱数を生成する</li><li>その小数の乱数に <code>20</code> を掛ける</li><li>別の関数 <code>Math.floor()</code> を使用して小数点以下の端数を切り捨て、最も近い整数を得る</li></ol>
|
||||
1. Use `Math.random()` to generate a random decimal number.
|
||||
2. Multiply that random decimal number by `20`.
|
||||
3. Use `Math.floor()` to round this number down to its nearest whole number.
|
||||
|
||||
`Math.random()` は決して `1` を返しません。そして切り捨てを行うため、`20` を取得する可能性はありません。 この方法では `0` ~ `19` の整数が得られます。
|
||||
Remember that `Math.random()` can never quite return a `1`, so it's impossible to actually get `20` since you are rounding down with `Math.floor()`. This process will give you a random whole number in the range from `0` to `19`.
|
||||
|
||||
すべてをまとめると次のようなコードになります。
|
||||
Putting everything together, this is what your code looks like:
|
||||
|
||||
```js
|
||||
Math.floor(Math.random() * 20);
|
||||
```
|
||||
|
||||
`Math.random()` を呼び出して、その結果に 20 を掛け、その値を `Math.floor()` 関数に渡して端数を切り捨て、最も近い整数を求めています。
|
||||
You are calling `Math.random()`, multiplying the result by 20, then passing the value to `Math.floor()` to round the value down to the nearest whole number.
|
||||
|
||||
# --instructions--
|
||||
|
||||
ここで紹介した方法で、`0` ~ `9` の整数の乱数を生成して返してください。
|
||||
Use this technique to generate and return a random whole number in the range from `0` to `9`.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -47,7 +49,7 @@ assert(
|
||||
assert(code.match(/Math.random/g).length >= 1);
|
||||
```
|
||||
|
||||
`Math.random` の結果に 10 を掛けて、0 ~ 9 の数値を求める必要があります。
|
||||
You should have multiplied the result of `Math.random` by 10 to make it a number in the range from zero to nine.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@@ -74,9 +76,6 @@ assert(code.match(/Math.floor/g).length >= 1);
|
||||
|
||||
```js
|
||||
function randomWholeNum() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
return Math.random();
|
||||
}
|
||||
```
|
||||
|
||||
@@ -9,11 +9,11 @@ dashedName: generate-random-whole-numbers-within-a-range
|
||||
|
||||
# --description--
|
||||
|
||||
前回は、ゼロから指定した数値までの整数の乱数を生成しましたが、2 つの特定の数値の範囲内で整数の乱数を生成することができます。
|
||||
You can generate a random whole number in the range from zero to a given number. You can also pick a different lower number for this range.
|
||||
|
||||
それには最小値 `min` と最大値 `max` を定義します。
|
||||
You'll call your minimum number `min` and your maximum number `max`.
|
||||
|
||||
ここでは次のような式を使用します。 このコードの動作を理解して確かめてみてください。
|
||||
This formula gives a random whole number in the range from `min` to `max`. このコードの動作を理解して確かめてみてください。
|
||||
|
||||
```js
|
||||
Math.floor(Math.random() * (max - min + 1)) + min
|
||||
@@ -21,7 +21,7 @@ Math.floor(Math.random() * (max - min + 1)) + min
|
||||
|
||||
# --instructions--
|
||||
|
||||
`myMin` から `myMax` までを範囲とする `randomRange` という関数を作成し、`myMin` 以上 `myMax` 以下の整数の乱数を返してください。
|
||||
Create a function called `randomRange` that takes a range `myMin` and `myMax` and returns a random whole number that's greater than or equal to `myMin` and less than or equal to `myMax`.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -87,9 +87,7 @@ for(var i = 0; i < 100; i++) {
|
||||
|
||||
```js
|
||||
function randomRange(myMin, myMax) {
|
||||
// Only change code below this line
|
||||
return 0;
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user