* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
cf1111c1c12feddfaeb2bdef | Generate Random Whole Numbers within a Range | 1 | 生成范围内的随机整数 |
Description
min
和最大数量max
。这是我们将使用的公式。花一点时间阅读它并尝试理解这段代码在做什么: Math.floor(Math.random() * (max - min + 1)) + min
Instructions
randomRange
的函数,它接受一个范围myMin
和myMax
并返回一个大于或等于myMin
的随机数,并且小于或等于myMax
(包括myMax
)。 Tests
tests:
- text: <code>randomRange</code>可以生成的最低随机数应该等于你的最小数量<code>myMin</code> 。
testString: assert(calcMin === 5);
- text: <code>randomRange</code>可以生成的最高随机数应该等于最大数量<code>myMax</code> 。
testString: assert(calcMax === 15);
- text: <code>randomRange</code>生成的随机数应该是整数,而不是小数。
testString: assert(randomRange(0,1) % 1 === 0 );
- text: <code>randomRange</code>应该同时使用<code>myMax</code>和<code>myMin</code> ,并在你的范围内返回一个随机数。
testString: assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})());
Challenge Seed
// Example
function ourRandomRange(ourMin, ourMax) {
return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}
ourRandomRange(1, 9);
// Only change code below this line.
function randomRange(myMin, myMax) {
return 0; // Change this line
}
// Change these values to test your function
var myRandom = randomRange(5, 15);
After Test
console.info('after the test');
Solution
// solution required