chore(i18n,learn): processed translations (#50114)

This commit is contained in:
camperbot
2023-04-20 19:38:02 +05:30
committed by GitHub
parent e5f1a8f73f
commit f0db9433e1
356 changed files with 62759 additions and 209 deletions

View File

@@ -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();
}
```

View File

@@ -9,11 +9,11 @@ dashedName: generate-random-whole-numbers-within-a-range
# --description--
我们之前生成的随机数是在 0 到某个数之间,现在我们要生成的随机数是在两个指定的数之间。
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--
创建一个函数 `randomRange`,参数为 `myMin` `myMax`,返回一个在 `myMin`(包括 myMin`myMax`(包括 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
}
```