From 1e28b76bf5c457c704491b56d39a24dbf078abe4 Mon Sep 17 00:00:00 2001 From: Ansh Malgotra Date: Wed, 26 Nov 2025 15:45:16 +0530 Subject: [PATCH] feat(curriculum): added 2 new steps to mathbot project for random integer generation (#64064) Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com> Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com> --- .../66ea845f54195c7020cc521b.md | 2 +- .../66eb480d996af5918d7c9c86.md | 9 +- .../66eb488c0129e192542f0865.md | 9 +- .../66eb499511810e932ca7eecc.md | 9 +- .../66ecdcf7c8d9a6f49094ffde.md | 9 +- .../66ece0b518f5dcf5930612ab.md | 9 +- .../66ece147323c91f654bf8dd9.md | 9 +- .../66ece75c0b840df77c7e20f0.md | 14 ++- .../69218a15fe536ee1be38aefb.md | 55 ++++++++++++ .../69218e46f4490b33f2481a1a.md | 85 +++++++++++++++++++ .../structure/blocks/workshop-mathbot.json | 72 ++++------------ 11 files changed, 211 insertions(+), 71 deletions(-) create mode 100644 curriculum/challenges/english/blocks/workshop-mathbot/69218a15fe536ee1be38aefb.md create mode 100644 curriculum/challenges/english/blocks/workshop-mathbot/69218e46f4490b33f2481a1a.md diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66ea845f54195c7020cc521b.md b/curriculum/challenges/english/blocks/workshop-mathbot/66ea845f54195c7020cc521b.md index cc9b190aa66..6a029853679 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66ea845f54195c7020cc521b.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66ea845f54195c7020cc521b.md @@ -33,7 +33,7 @@ Your `randomNum2` variable should be a number. assert.isNumber(randomNum2); ``` -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. +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. ```js assert.isAtLeast(randomNum2, min); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66eb480d996af5918d7c9c86.md b/curriculum/challenges/english/blocks/workshop-mathbot/66eb480d996af5918d7c9c86.md index 46f288425e4..b7d479a7696 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66eb480d996af5918d7c9c86.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66eb480d996af5918d7c9c86.md @@ -1,8 +1,8 @@ --- id: 66eb480d996af5918d7c9c86 -title: Step 8 +title: Step 10 challengeType: 1 -dashedName: step-8 +dashedName: step-10 --- # --description-- @@ -46,6 +46,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); + +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); --fcc-editable-region-- --fcc-editable-region-- diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66eb488c0129e192542f0865.md b/curriculum/challenges/english/blocks/workshop-mathbot/66eb488c0129e192542f0865.md index 11e8d95d2d2..bf1826ff3a6 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66eb488c0129e192542f0865.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66eb488c0129e192542f0865.md @@ -1,8 +1,8 @@ --- id: 66eb488c0129e192542f0865 -title: Step 9 +title: Step 11 challengeType: 1 -dashedName: step-9 +dashedName: step-11 --- # --description-- @@ -80,6 +80,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); --fcc-editable-region-- diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66eb499511810e932ca7eecc.md b/curriculum/challenges/english/blocks/workshop-mathbot/66eb499511810e932ca7eecc.md index 039e1dbffae..29deeab2699 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66eb499511810e932ca7eecc.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66eb499511810e932ca7eecc.md @@ -1,8 +1,8 @@ --- id: 66eb499511810e932ca7eecc -title: Step 10 +title: Step 12 challengeType: 1 -dashedName: step-10 +dashedName: step-12 --- # --description-- @@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); const numRoundedUp = Math.ceil(3.2); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66ecdcf7c8d9a6f49094ffde.md b/curriculum/challenges/english/blocks/workshop-mathbot/66ecdcf7c8d9a6f49094ffde.md index 65045cf5090..74204c8760f 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66ecdcf7c8d9a6f49094ffde.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66ecdcf7c8d9a6f49094ffde.md @@ -1,8 +1,8 @@ --- id: 66ecdcf7c8d9a6f49094ffde -title: Step 11 +title: Step 13 challengeType: 1 -dashedName: step-11 +dashedName: step-13 --- # --description-- @@ -100,6 +100,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); const numRoundedUp = Math.ceil(3.2); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66ece0b518f5dcf5930612ab.md b/curriculum/challenges/english/blocks/workshop-mathbot/66ece0b518f5dcf5930612ab.md index 0b26f13bf19..f82703af49d 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66ece0b518f5dcf5930612ab.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66ece0b518f5dcf5930612ab.md @@ -1,8 +1,8 @@ --- id: 66ece0b518f5dcf5930612ab -title: Step 12 +title: Step 14 challengeType: 1 -dashedName: step-12 +dashedName: step-14 --- # --description-- @@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); const numRoundedUp = Math.ceil(3.2); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66ece147323c91f654bf8dd9.md b/curriculum/challenges/english/blocks/workshop-mathbot/66ece147323c91f654bf8dd9.md index 2eb83e293ee..ce6d71ddbcc 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66ece147323c91f654bf8dd9.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66ece147323c91f654bf8dd9.md @@ -1,8 +1,8 @@ --- id: 66ece147323c91f654bf8dd9 -title: Step 13 +title: Step 15 challengeType: 1 -dashedName: step-13 +dashedName: step-15 --- # --description-- @@ -96,6 +96,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); const numRoundedUp = Math.ceil(3.2); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/66ece75c0b840df77c7e20f0.md b/curriculum/challenges/english/blocks/workshop-mathbot/66ece75c0b840df77c7e20f0.md index e64ae792b4c..bb00c27612e 100644 --- a/curriculum/challenges/english/blocks/workshop-mathbot/66ece75c0b840df77c7e20f0.md +++ b/curriculum/challenges/english/blocks/workshop-mathbot/66ece75c0b840df77c7e20f0.md @@ -1,8 +1,8 @@ --- id: 66ece75c0b840df77c7e20f0 -title: Step 14 +title: Step 16 challengeType: 1 -dashedName: step-14 +dashedName: step-16 --- # --description-- @@ -47,6 +47,11 @@ console.log("The Math.floor() method rounds the value down to the nearest whole const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log("The Math.ceil() method rounds the value up to the nearest whole integer."); const numRoundedUp = Math.ceil(3.2); @@ -101,6 +106,11 @@ console.log( const numRoundedDown = Math.floor(6.7); console.log(numRoundedDown); +console.log("Now, generate a random integer between two values."); + +const randomInt = Math.floor(Math.random() * (max - min) + min); +console.log(randomInt); + console.log( "The Math.ceil() method rounds the value up to the nearest whole integer." ); diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/69218a15fe536ee1be38aefb.md b/curriculum/challenges/english/blocks/workshop-mathbot/69218a15fe536ee1be38aefb.md new file mode 100644 index 00000000000..7bf09544823 --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-mathbot/69218a15fe536ee1be38aefb.md @@ -0,0 +1,55 @@ +--- +id: 69218a15fe536ee1be38aefb +title: Step 8 +challengeType: 1 +dashedName: step-8 +--- + +# --description-- + +The next portion of the workshop is to review how to generate a random integer between two values. + +Start by adding another `console.log()` that logs the message `"Now, generate a random integer between two values."` to the console. + +In the next step, you will generate a random integer between the values of the `min` and `max` variables you have already created. + +# --hints-- + +You should have a `console.log()` that logs the message `"Now, generate a random integer between two values."`. + +```js +assert.match(code, /console\.log\((`|'|")\s*Now,\s+generate\s+a\s+random\s+integer\s+between\s+two\s+values\.\s*\1\);?/); +``` + +# --seed-- + +## --seed-contents-- + +```js +const botName = "MathBot"; +const greeting = `Hi there! My name is ${botName} and I am here to teach you about the Math object!`; + +console.log(greeting); + +console.log("The Math.random() method returns a pseudo random number greater than or equal to 0 and less than 1."); + +const randomNum = Math.random(); +console.log(randomNum); + +console.log("Now, generate a random number between two values."); + +const min = 1; +const max = 100; + +const randomNum2 = Math.random() * (max - min) + min; +console.log(randomNum2); + +console.log("The Math.floor() method rounds the value down to the nearest whole integer."); + +const numRoundedDown = Math.floor(6.7); +console.log(numRoundedDown); + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/blocks/workshop-mathbot/69218e46f4490b33f2481a1a.md b/curriculum/challenges/english/blocks/workshop-mathbot/69218e46f4490b33f2481a1a.md new file mode 100644 index 00000000000..3813571d4db --- /dev/null +++ b/curriculum/challenges/english/blocks/workshop-mathbot/69218e46f4490b33f2481a1a.md @@ -0,0 +1,85 @@ +--- +id: 69218e46f4490b33f2481a1a +title: Step 9 +challengeType: 1 +dashedName: step-9 +--- + +# --description-- + +The formula to generate a random integer between two values is the following: + +```js +Math.floor(Math.random() * (maximum - minimum) + minimum); +``` + +This will produce a result that is a integer between two values. + +Create a variable called `randomInt` and assign it the result of generating a value between the `min` and `max` values. + +Then, log the `randomInt` variable to see the result. Try refreshing the page to see different results. + +# --hints-- + +You should have a variable called `randomInt`. + +```js +assert.isNotNull(randomInt); +``` + +Your `randomInt` variable should be a number. + +```js +assert.isNumber(randomInt); +``` + +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. + +```js +assert.isAtLeast(randomInt, min); +assert.isAtMost(randomInt, max); + +// check for whole random numbers just in case a camper does this +assert.notMatch(code, /randomInt\s*=\s*\d+;?/); +``` + +You should log the `randomInt` variable to the console. + +```js +assert.match(code, /console\.log\(\s*randomInt\s*\);?/); +``` + + +# --seed-- + +## --seed-contents-- + +```js +const botName = "MathBot"; +const greeting = `Hi there! My name is ${botName} and I am here to teach you about the Math object!`; + +console.log(greeting); + +console.log("The Math.random() method returns a pseudo random number greater than or equal to 0 and less than 1."); + +const randomNum = Math.random(); +console.log(randomNum); + +console.log("Now, generate a random number between two values."); + +const min = 1; +const max = 100; + +const randomNum2 = Math.random() * (max - min) + min; +console.log(randomNum2); + +console.log("The Math.floor() method rounds the value down to the nearest whole integer."); + +const numRoundedDown = Math.floor(6.7); +console.log(numRoundedDown); + +console.log("Now, generate a random integer between two values."); +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/structure/blocks/workshop-mathbot.json b/curriculum/structure/blocks/workshop-mathbot.json index 8dc360eeac4..e981c3463a7 100644 --- a/curriculum/structure/blocks/workshop-mathbot.json +++ b/curriculum/structure/blocks/workshop-mathbot.json @@ -7,62 +7,22 @@ "hasEditableBoundaries": true, "dashedName": "workshop-mathbot", "challengeOrder": [ - { - "id": "66ea7adae8053065a64f9002", - "title": "Step 1" - }, - { - "id": "66ea7e7399244c6d4b6052a1", - "title": "Step 2" - }, - { - "id": "66ea7fc048a6e26e33c598fe", - "title": "Step 3" - }, - { - "id": "66ea8239b9eeb76f12299030", - "title": "Step 4" - }, - { - "id": "66ea845f54195c7020cc521b", - "title": "Step 5" - }, - { - "id": "66ea89c25e1bd871688eba6a", - "title": "Step 6" - }, - { - "id": "66eb3ec3b07dfe8f898646c0", - "title": "Step 7" - }, - { - "id": "66eb480d996af5918d7c9c86", - "title": "Step 8" - }, - { - "id": "66eb488c0129e192542f0865", - "title": "Step 9" - }, - { - "id": "66eb499511810e932ca7eecc", - "title": "Step 10" - }, - { - "id": "66ecdcf7c8d9a6f49094ffde", - "title": "Step 11" - }, - { - "id": "66ece0b518f5dcf5930612ab", - "title": "Step 12" - }, - { - "id": "66ece147323c91f654bf8dd9", - "title": "Step 13" - }, - { - "id": "66ece75c0b840df77c7e20f0", - "title": "Step 14" - } + { "id": "66ea7adae8053065a64f9002", "title": "Step 1" }, + { "id": "66ea7e7399244c6d4b6052a1", "title": "Step 2" }, + { "id": "66ea7fc048a6e26e33c598fe", "title": "Step 3" }, + { "id": "66ea8239b9eeb76f12299030", "title": "Step 4" }, + { "id": "66ea845f54195c7020cc521b", "title": "Step 5" }, + { "id": "66ea89c25e1bd871688eba6a", "title": "Step 6" }, + { "id": "66eb3ec3b07dfe8f898646c0", "title": "Step 7" }, + { "id": "69218a15fe536ee1be38aefb", "title": "Step 8" }, + { "id": "69218e46f4490b33f2481a1a", "title": "Step 9" }, + { "id": "66eb480d996af5918d7c9c86", "title": "Step 10" }, + { "id": "66eb488c0129e192542f0865", "title": "Step 11" }, + { "id": "66eb499511810e932ca7eecc", "title": "Step 12" }, + { "id": "66ecdcf7c8d9a6f49094ffde", "title": "Step 13" }, + { "id": "66ece0b518f5dcf5930612ab", "title": "Step 14" }, + { "id": "66ece147323c91f654bf8dd9", "title": "Step 15" }, + { "id": "66ece75c0b840df77c7e20f0", "title": "Step 16" } ], "helpCategory": "JavaScript" }