mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-05 16:00:38 -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--
|
||||
|
||||
Замість генерації випадкового цілого числа між нулем і заданим числом, як ми робили це раніше, ми можемо згенерувати випадкове ціле число, що потрапляє в діапазон двох конкретних чисел.
|
||||
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` і менше або дорівнює `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