Skip to content

Commit d08f95f

Browse files
authored
Primitive Challenge 3: Random number generation distribution fix
Updated phrasing for clarity and consistency in challenges.
1 parent 8b9f365 commit d08f95f

File tree

1 file changed

+10
-10
lines changed
  • web/src/app/challenges/primitives

1 file changed

+10
-10
lines changed

web/src/app/challenges/primitives/page.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ export const metadata = {
22
title: "Primitives | Challenges",
33
}
44

5-
### 1. Swap two integers present in variables num1 and num2 without using temporary variable
5+
### 1. Swap two integers present in variables num1 and num2 without using a temporary variable
66

7-
- The swapping of 2 variables is possible with simple Destructuring assignment using array
8-
- Traditional approach of swapping by using the given variables is also achievable
7+
- The swapping of 2 variables is possible with simple Destructuring assignment using an array
8+
- The traditional approach of swapping by using the given variables is also achievable
99

1010
```js copy
1111
let num1 = 10, num2 = 20;
@@ -21,11 +21,11 @@ num1 = num1 - num2;
2121

2222
**Notes**
2323

24-
2nd solution can fail due to overflow of number range if the numbers are very big
24+
2nd solution can fail due to overflow of the number range if the numbers are very big
2525

2626
---
2727

28-
### 2. Write a function which returns true if given value of number is an integer without using any inbuilt functions
28+
### 2. Write a function that returns true if the given value of a number is an integer without using any inbuilt functions
2929

3030
```js copy
3131
// Example
@@ -34,7 +34,7 @@ isInt(12.2); // false
3434
isInt(0.3); // false
3535
```
3636

37-
- Modulo operator can be used to check if there is a remainder left when divided by 1
37+
- The modulo operator can be used to check if there is a remainder left when divided by 1
3838

3939
```js copy
4040
function isInt(value) {
@@ -44,13 +44,13 @@ function isInt(value) {
4444

4545
---
4646

47-
### 3. Create a function which returns a random number in the given range of values both inclusive
47+
### 3. Create a function that returns a random number in the given range of values, both inclusive
4848

4949
- `Math.random` function returns a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive)
5050

5151
```js copy
5252
function randomNumberGeneratorInRange(rangeStart, rangeEnd) {
53-
return rangeStart + Math.round(Math.random() * (rangeEnd - rangeStart));
53+
return rangeStart + Math.floor(Math.random() * (rangeEnd - rangeStart + 1))
5454
}
5555

5656
randomNumberGeneratorInRange(10, 50); // 12
@@ -68,8 +68,8 @@ Usage of `Math.round` depends on the logic used to accomplish the requirement
6868

6969
### 4. Write a program to reverse a string
7070

71-
- String can be reversed by iterating it and storing it in reverse order
72-
- String can also be reversed by converting it to array, then joining it after reversing
71+
- A string can be reversed by iterating over it and storing it in reverse order
72+
- A string can also be reversed by converting it to an array, then joining it after reversing
7373

7474
```js copy
7575
const str = "JavaScript is awesome";

0 commit comments

Comments
 (0)