1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| cf1111c1c11feddfaeb9bdef | JavaScript で小数の乱数を生成する | 1 | https://scrimba.com/c/cyWJJs3 | 18185 | generate-random-fractions-with-javascript |
--description--
乱数はランダムな動作を作成するのに便利です。
JavaScript には、0 (含む) から 1 (含まない) の間の小数の乱数を生成する Math.random() 関数があります。 つまり、Math.random() は 0 を返すことはありますが、1 を返すことは決してありません。
注意: 代入演算子による値の格納の場合と同様に、すべての関数呼び出しは return が実行される前に解決されるため、Math.random() 関数の値を return することができます。
--instructions--
0 の代わりに乱数を返すように、randomFraction を変更してください。
--hints--
randomFraction は乱数を返す必要があります。
assert(typeof randomFraction() === 'number');
randomFraction が返す数値は小数である必要があります。
assert((randomFraction() + '').match(/\./g));
Math.random を使用して、小数の乱数を生成する必要があります。
assert(code.match(/Math\.random/g).length >= 0);
--seed--
--after-user-code--
(function(){return randomFraction();})();
--seed-contents--
function randomFraction() {
// Only change code below this line
return 0;
// Only change code above this line
}
--solutions--
function randomFraction() {
return Math.random();
}