Skip to content

Commit 1e28b76

Browse files
shokuyanshmajestic-owl448Dario-DC
authored
feat(curriculum): added 2 new steps to mathbot project for random integer generation (freeCodeCamp#64064)
Co-authored-by: majestic-owl448 <[email protected]> Co-authored-by: Dario <[email protected]>
1 parent a89054d commit 1e28b76

11 files changed

+211
-71
lines changed

curriculum/challenges/english/blocks/workshop-mathbot/66ea845f54195c7020cc521b.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Your `randomNum2` variable should be a number.
3333
assert.isNumber(randomNum2);
3434
```
3535

36-
You should assign the result of generating a value between the `min` and `max` values. Make sure not to hardcode a value. You should use the formulae provided above.
36+
You should assign the result of generating a value between the `min` and `max` values. Make sure not to hardcode a value. You should use the formula provided above.
3737

3838
```js
3939
assert.isAtLeast(randomNum2, min);

curriculum/challenges/english/blocks/workshop-mathbot/66eb480d996af5918d7c9c86.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66eb480d996af5918d7c9c86
3-
title: Step 8
3+
title: Step 10
44
challengeType: 1
5-
dashedName: step-8
5+
dashedName: step-10
66
---
77

88
# --description--
@@ -46,6 +46,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
4646

4747
const numRoundedDown = Math.floor(6.7);
4848
console.log(numRoundedDown);
49+
50+
console.log("Now, generate a random integer between two values.");
51+
52+
const randomInt = Math.floor(Math.random() * (max - min) + min);
53+
console.log(randomInt);
4954
--fcc-editable-region--
5055

5156
--fcc-editable-region--

curriculum/challenges/english/blocks/workshop-mathbot/66eb488c0129e192542f0865.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66eb488c0129e192542f0865
3-
title: Step 9
3+
title: Step 11
44
challengeType: 1
5-
dashedName: step-9
5+
dashedName: step-11
66
---
77

88
# --description--
@@ -80,6 +80,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
8080
const numRoundedDown = Math.floor(6.7);
8181
console.log(numRoundedDown);
8282

83+
console.log("Now, generate a random integer between two values.");
84+
85+
const randomInt = Math.floor(Math.random() * (max - min) + min);
86+
console.log(randomInt);
87+
8388
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
8489

8590
--fcc-editable-region--

curriculum/challenges/english/blocks/workshop-mathbot/66eb499511810e932ca7eecc.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66eb499511810e932ca7eecc
3-
title: Step 10
3+
title: Step 12
44
challengeType: 1
5-
dashedName: step-10
5+
dashedName: step-12
66
---
77

88
# --description--
@@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
4747
const numRoundedDown = Math.floor(6.7);
4848
console.log(numRoundedDown);
4949

50+
console.log("Now, generate a random integer between two values.");
51+
52+
const randomInt = Math.floor(Math.random() * (max - min) + min);
53+
console.log(randomInt);
54+
5055
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
5156

5257
const numRoundedUp = Math.ceil(3.2);

curriculum/challenges/english/blocks/workshop-mathbot/66ecdcf7c8d9a6f49094ffde.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66ecdcf7c8d9a6f49094ffde
3-
title: Step 11
3+
title: Step 13
44
challengeType: 1
5-
dashedName: step-11
5+
dashedName: step-13
66
---
77

88
# --description--
@@ -100,6 +100,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
100100
const numRoundedDown = Math.floor(6.7);
101101
console.log(numRoundedDown);
102102

103+
console.log("Now, generate a random integer between two values.");
104+
105+
const randomInt = Math.floor(Math.random() * (max - min) + min);
106+
console.log(randomInt);
107+
103108
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
104109

105110
const numRoundedUp = Math.ceil(3.2);

curriculum/challenges/english/blocks/workshop-mathbot/66ece0b518f5dcf5930612ab.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66ece0b518f5dcf5930612ab
3-
title: Step 12
3+
title: Step 14
44
challengeType: 1
5-
dashedName: step-12
5+
dashedName: step-14
66
---
77

88
# --description--
@@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
4747
const numRoundedDown = Math.floor(6.7);
4848
console.log(numRoundedDown);
4949

50+
console.log("Now, generate a random integer between two values.");
51+
52+
const randomInt = Math.floor(Math.random() * (max - min) + min);
53+
console.log(randomInt);
54+
5055
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
5156

5257
const numRoundedUp = Math.ceil(3.2);

curriculum/challenges/english/blocks/workshop-mathbot/66ece147323c91f654bf8dd9.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66ece147323c91f654bf8dd9
3-
title: Step 13
3+
title: Step 15
44
challengeType: 1
5-
dashedName: step-13
5+
dashedName: step-15
66
---
77

88
# --description--
@@ -96,6 +96,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
9696
const numRoundedDown = Math.floor(6.7);
9797
console.log(numRoundedDown);
9898

99+
console.log("Now, generate a random integer between two values.");
100+
101+
const randomInt = Math.floor(Math.random() * (max - min) + min);
102+
console.log(randomInt);
103+
99104
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
100105

101106
const numRoundedUp = Math.ceil(3.2);

curriculum/challenges/english/blocks/workshop-mathbot/66ece75c0b840df77c7e20f0.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: 66ece75c0b840df77c7e20f0
3-
title: Step 14
3+
title: Step 16
44
challengeType: 1
5-
dashedName: step-14
5+
dashedName: step-16
66
---
77

88
# --description--
@@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole
4747
const numRoundedDown = Math.floor(6.7);
4848
console.log(numRoundedDown);
4949

50+
console.log("Now, generate a random integer between two values.");
51+
52+
const randomInt = Math.floor(Math.random() * (max - min) + min);
53+
console.log(randomInt);
54+
5055
console.log("The Math.ceil() method rounds the value up to the nearest whole integer.");
5156

5257
const numRoundedUp = Math.ceil(3.2);
@@ -101,6 +106,11 @@ console.log(
101106
const numRoundedDown = Math.floor(6.7);
102107
console.log(numRoundedDown);
103108

109+
console.log("Now, generate a random integer between two values.");
110+
111+
const randomInt = Math.floor(Math.random() * (max - min) + min);
112+
console.log(randomInt);
113+
104114
console.log(
105115
"The Math.ceil() method rounds the value up to the nearest whole integer."
106116
);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: 69218a15fe536ee1be38aefb
3+
title: Step 8
4+
challengeType: 1
5+
dashedName: step-8
6+
---
7+
8+
# --description--
9+
10+
The next portion of the workshop is to review how to generate a random integer between two values.
11+
12+
Start by adding another `console.log()` that logs the message `"Now, generate a random integer between two values."` to the console.
13+
14+
In the next step, you will generate a random integer between the values of the `min` and `max` variables you have already created.
15+
16+
# --hints--
17+
18+
You should have a `console.log()` that logs the message `"Now, generate a random integer between two values."`.
19+
20+
```js
21+
assert.match(code, /console\.log\((`|'|")\s*Now,\s+generate\s+a\s+random\s+integer\s+between\s+two\s+values\.\s*\1\);?/);
22+
```
23+
24+
# --seed--
25+
26+
## --seed-contents--
27+
28+
```js
29+
const botName = "MathBot";
30+
const greeting = `Hi there! My name is ${botName} and I am here to teach you about the Math object!`;
31+
32+
console.log(greeting);
33+
34+
console.log("The Math.random() method returns a pseudo random number greater than or equal to 0 and less than 1.");
35+
36+
const randomNum = Math.random();
37+
console.log(randomNum);
38+
39+
console.log("Now, generate a random number between two values.");
40+
41+
const min = 1;
42+
const max = 100;
43+
44+
const randomNum2 = Math.random() * (max - min) + min;
45+
console.log(randomNum2);
46+
47+
console.log("The Math.floor() method rounds the value down to the nearest whole integer.");
48+
49+
const numRoundedDown = Math.floor(6.7);
50+
console.log(numRoundedDown);
51+
52+
--fcc-editable-region--
53+
54+
--fcc-editable-region--
55+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
id: 69218e46f4490b33f2481a1a
3+
title: Step 9
4+
challengeType: 1
5+
dashedName: step-9
6+
---
7+
8+
# --description--
9+
10+
The formula to generate a random integer between two values is the following:
11+
12+
```js
13+
Math.floor(Math.random() * (maximum - minimum) + minimum);
14+
```
15+
16+
This will produce a result that is a integer between two values.
17+
18+
Create a variable called `randomInt` and assign it the result of generating a value between the `min` and `max` values.
19+
20+
Then, log the `randomInt` variable to see the result. Try refreshing the page to see different results.
21+
22+
# --hints--
23+
24+
You should have a variable called `randomInt`.
25+
26+
```js
27+
assert.isNotNull(randomInt);
28+
```
29+
30+
Your `randomInt` variable should be a number.
31+
32+
```js
33+
assert.isNumber(randomInt);
34+
```
35+
36+
You should assign the result of generating a value between the `min` and `max` values. Make sure not to hardcode a value. You should use the formula provided above.
37+
38+
```js
39+
assert.isAtLeast(randomInt, min);
40+
assert.isAtMost(randomInt, max);
41+
42+
// check for whole random numbers just in case a camper does this
43+
assert.notMatch(code, /randomInt\s*=\s*\d+;?/);
44+
```
45+
46+
You should log the `randomInt` variable to the console.
47+
48+
```js
49+
assert.match(code, /console\.log\(\s*randomInt\s*\);?/);
50+
```
51+
52+
53+
# --seed--
54+
55+
## --seed-contents--
56+
57+
```js
58+
const botName = "MathBot";
59+
const greeting = `Hi there! My name is ${botName} and I am here to teach you about the Math object!`;
60+
61+
console.log(greeting);
62+
63+
console.log("The Math.random() method returns a pseudo random number greater than or equal to 0 and less than 1.");
64+
65+
const randomNum = Math.random();
66+
console.log(randomNum);
67+
68+
console.log("Now, generate a random number between two values.");
69+
70+
const min = 1;
71+
const max = 100;
72+
73+
const randomNum2 = Math.random() * (max - min) + min;
74+
console.log(randomNum2);
75+
76+
console.log("The Math.floor() method rounds the value down to the nearest whole integer.");
77+
78+
const numRoundedDown = Math.floor(6.7);
79+
console.log(numRoundedDown);
80+
81+
console.log("Now, generate a random integer between two values.");
82+
--fcc-editable-region--
83+
84+
--fcc-editable-region--
85+
```

0 commit comments

Comments
 (0)