81 lines
3.4 KiB
Markdown
81 lines
3.4 KiB
Markdown
|
---
|
||
|
id: cf1111c1c12feddfaeb2bdef
|
||
|
title: Generate Random Whole Numbers within a Range
|
||
|
challengeType: 1
|
||
|
videoUrl: ''
|
||
|
localeTitle: توليد أرقام كاملة عشوائية داخل نطاق
|
||
|
---
|
||
|
|
||
|
## Description
|
||
|
<section id="description"> بدلاً من إنشاء رقم عشوائي بين الصفر ورقم معين كما فعلنا من قبل ، يمكننا إنشاء رقم عشوائي يقع ضمن نطاق من رقمين محددين. للقيام بذلك، ونحن سوف تحدد العدد الأدنى من <code>min</code> والحد الأقصى ل <code>max</code> . إليكم الصيغة التي سنستخدمها. خذ لحظة في قراءته وحاول فهم ما يفعله هذا الكود: <code>Math.floor(Math.random() * (max - min + 1)) + min</code> </section>
|
||
|
|
||
|
## Instructions
|
||
|
<section id="instructions"> قم بإنشاء دالة تسمى <code>randomRange</code> والتي تأخذ نطاق <code>myMin</code> و <code>myMax</code> وتقوم بإرجاع رقم عشوائي أكبر من أو يساوي <code>myMin</code> ، وهو أقل من أو يساوي <code>myMax</code> ، شامل. </section>
|
||
|
|
||
|
## Tests
|
||
|
<section id='tests'>
|
||
|
|
||
|
```yml
|
||
|
tests:
|
||
|
- text: يجب أن يكون العدد العشوائي الأدنى الذي يمكن إنشاؤه بواسطة <code>randomRange</code> مساوياً للحد الأدنى للرقم ، <code>myMin</code> .
|
||
|
testString: 'assert(calcMin === 5, "The lowest random number that can be generated by <code>randomRange</code> should be equal to your minimum number, <code>myMin</code>.");'
|
||
|
- text: يجب أن يكون الرقم العشوائي الأعلى الذي يمكن إنشاؤه بواسطة <code>randomRange</code> مساويا <code>myMax</code> عدد ممكن ، <code>myMax</code> .
|
||
|
testString: 'assert(calcMax === 15, "The highest random number that can be generated by <code>randomRange</code> should be equal to your maximum number, <code>myMax</code>.");'
|
||
|
- text: يجب أن يكون الرقم العشوائي الذي تم إنشاؤه بواسطة <code>randomRange</code> عددًا صحيحًا وليس عشريًا.
|
||
|
testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by <code>randomRange</code> should be an integer, not a decimal.");'
|
||
|
- 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;}})(), "<code>randomRange</code> should use both <code>myMax</code> and <code>myMin</code>, and return a random number in your range.");'
|
||
|
|
||
|
```
|
||
|
|
||
|
</section>
|
||
|
|
||
|
## Challenge Seed
|
||
|
<section id='challengeSeed'>
|
||
|
|
||
|
<div id='js-seed'>
|
||
|
|
||
|
```js
|
||
|
// 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);
|
||
|
|
||
|
```
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
### After Test
|
||
|
<div id='js-teardown'>
|
||
|
|
||
|
```js
|
||
|
console.info('after the test');
|
||
|
```
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
## Solution
|
||
|
<section id='solution'>
|
||
|
|
||
|
```js
|
||
|
// solution required
|
||
|
```
|
||
|
</section>
|