mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 21:03:58 -05:00
1.0 KiB
1.0 KiB
id, title, challengeType, videoUrl, forumTopicId
| id | title | challengeType | videoUrl | forumTopicId |
|---|---|---|---|---|
| cf1111c1c11feddfaeb9bdef | 使用 JavaScript 生成随机分数 | 1 | https://scrimba.com/c/cyWJJs3 | 18185 |
--description--
随机数非常适合用来创建随机行为。
Math.random()用来生成一个在0(包括 0)到1(不包括 1)之间的随机小数,因此Math.random()可能返回 0 但绝不会返回 1。
提示
使用赋值运算符存储值这一节讲过,所有函数调用将在return执行之前解析,因此我们可以返回Math.random()函数的值。
--instructions--
更改randomFraction使其返回一个随机数而不是0。
--hints--
randomFraction应该返回一个随机数。
assert(typeof randomFraction() === 'number');
randomFraction应该返回一个小数。
assert((randomFraction() + '').match(/\./g));
需要使用Math.random生成随机的小数。
assert(code.match(/Math\.random/g).length >= 0);