mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
feat(curriculum): adding the Mathbot workshop to frontend cert (#56173)
Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
co-authored by
Dario-DC
parent
eca52a9e61
commit
41baee79a8
@@ -2087,7 +2087,12 @@
|
||||
]
|
||||
},
|
||||
"hxwa": { "title": "141", "intro": [] },
|
||||
"xkbo": { "title": "142", "intro": [] },
|
||||
"workshop-mathbot": {
|
||||
"title": "Build a Mathbot",
|
||||
"intro": [
|
||||
"In this workshop, you will review how to work with the different Math object methods by building a Mathbot."
|
||||
]
|
||||
},
|
||||
"lab-fortune-teller": {
|
||||
"title": "Build a Fortune Teller",
|
||||
"intro": [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Build a Mathbot
|
||||
block: workshop-mathbot
|
||||
superBlock: front-end-development
|
||||
---
|
||||
|
||||
## Introduction to the Build a Mathbot
|
||||
|
||||
This is a test for the new project-based curriculum.
|
||||
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "Build a Mathbot",
|
||||
"blockType": "workshop",
|
||||
"isUpcomingChange": true,
|
||||
"usesMultifileEditor": true,
|
||||
"hasEditableBoundaries": true,
|
||||
"dashedName": "workshop-mathbot",
|
||||
"order": 142,
|
||||
"superBlock": "front-end-development",
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"helpCategory": "JavaScript"
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
---
|
||||
id: 66ea7adae8053065a64f9002
|
||||
title: Step 1
|
||||
challengeType: 1
|
||||
dashedName: step-1
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this workshop, you will review working with the different `Math` object methods by building a Mathbot. This Mathbot will log some math operations and messages to the console in efforts to teach you about JavaScript's `Math` object.
|
||||
|
||||
For this first step, start by creating a variable called `botName` and assign it the string value of `"MathBot"`.
|
||||
|
||||
Then, create another variable called `greeting` and assign it the sentence `"Hi there! My name is [botName goes here] and I am here to teach you about the Math object!"`. In place of the `[botName goes here]` placeholder, use the `botName` variable.
|
||||
|
||||
You are free to use template literals or string concatenation with the `+` operator to achieve this.
|
||||
|
||||
Finally, log the `greeting` variable to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `botName`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(botName);
|
||||
```
|
||||
|
||||
Your `botName` variable should be a string.
|
||||
|
||||
```js
|
||||
assert.isString(botName);
|
||||
```
|
||||
|
||||
You should assign the string value `"MathBot"` to the `botName` variable.
|
||||
|
||||
```js
|
||||
assert.strictEqual(botName, "MathBot");
|
||||
```
|
||||
|
||||
You should have a variable called `greeting`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(greeting);
|
||||
```
|
||||
|
||||
Your `greeting` variable should be a string.
|
||||
|
||||
```js
|
||||
assert.isString(greeting);
|
||||
```
|
||||
|
||||
You should use assign the following sentence to the `greeting` variable: `"Hi there! My name is [MathBot goes here] and I am here to teach you about the Math object!"`. Make sure to replace `[MathBot goes here]` with the `botName` variable.
|
||||
|
||||
```js
|
||||
assert.strictEqual(greeting, "Hi there! My name is MathBot and I am here to teach you about the Math object!");
|
||||
```
|
||||
|
||||
You should log the `greeting` variable to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(greeting\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
---
|
||||
id: 66ea7e7399244c6d4b6052a1
|
||||
title: Step 2
|
||||
challengeType: 1
|
||||
dashedName: step-2
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The next part of the workshop will review how the `Math.random()` method works.
|
||||
|
||||
Start by adding another `console.log()` that logs the string `"The Math.random() method returns a pseudo random number between 0 and less than 1."` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `console.log()` that logs the string `"The Math.random() method returns a pseudo random number between 0 and less than 1."`.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((`|'|")\s*The\s+Math\.random\(\)\s+method\s+returns\s+a\s+pseudo\s+random\s+number\s+between\s+0\s+and\s+less\s+than\s+1\.\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);
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
---
|
||||
id: 66ea7fc048a6e26e33c598fe
|
||||
title: Step 3
|
||||
challengeType: 1
|
||||
dashedName: step-3
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Now, it is time to generate a random number using the `Math.random()` method.
|
||||
|
||||
Create a variable called `randomNum` and assign it the value of the result of calling the `Math.random()` method.
|
||||
|
||||
Then, log the `randomNum` variable to the console.
|
||||
|
||||
Try adding a space in the code to re-run the bot and see different random numbers that are generated.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `randomNum`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(randomNum);
|
||||
```
|
||||
|
||||
You should assign the result of calling the `Math.random()` method to the `randomNum` variable.
|
||||
|
||||
```js
|
||||
assert.match(code, /randomNum\s*=\s*Math\.random\(\);?/);
|
||||
```
|
||||
|
||||
You should not hardcode a random number for the `randomNum` variable. Make sure to use the `Math.random()` method to generate the random number.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /randomNum\s*=\s*0\.\d+;?/);
|
||||
|
||||
// check for whole random numbers just in case a camper does this
|
||||
assert.notMatch(code, /randomNum\s*=\s*\d+;?/);
|
||||
```
|
||||
|
||||
You should log the `randomNum` variable to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*randomNum\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 between 0 and less than 1.");
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
---
|
||||
id: 66ea8239b9eeb76f12299030
|
||||
title: Step 4
|
||||
challengeType: 1
|
||||
dashedName: step-4
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The next portion of the workshop is to review how to generate a random number between two values.
|
||||
|
||||
Start by adding another `console.log()` that logs the message `"Now, generate a random number between two values."` to the console.
|
||||
|
||||
Then, create a variable called `min` and assign it the value of `1` and create a variable called `max` and assign it the value of `100`.
|
||||
|
||||
In the next step, you will generate a random number between these two values.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `console.log()` that logs the message `"Now, generate a random number between two values."`.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((`|'|")\s*Now,\s+generate\s+a\s+random\s+number\s+between\s+two\s+values\.\s*\1\);?/);
|
||||
```
|
||||
|
||||
You should have a variable called `min`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(min);
|
||||
```
|
||||
|
||||
Your `min` variable should be a number.
|
||||
|
||||
```js
|
||||
assert.isNumber(min);
|
||||
```
|
||||
|
||||
You should assign the number `1` to your `min` variable.
|
||||
|
||||
```js
|
||||
assert.equal(min, 1);
|
||||
```
|
||||
|
||||
You should have a variable called `max`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(max);
|
||||
```
|
||||
|
||||
Your `max` variable should be a number.
|
||||
|
||||
```js
|
||||
assert.isNumber(max);
|
||||
```
|
||||
|
||||
You should assign the number `100` to your `max` variable.
|
||||
|
||||
```js
|
||||
assert.equal(max, 100);
|
||||
```
|
||||
|
||||
# --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 between 0 and less than 1.");
|
||||
|
||||
const randomNum = Math.random();
|
||||
console.log(randomNum);
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
---
|
||||
id: 66ea845f54195c7020cc521b
|
||||
title: Step 5
|
||||
challengeType: 1
|
||||
dashedName: step-5
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The formula to generate a random number between two values is the following:
|
||||
|
||||
```js
|
||||
Math.random() * (maximum - minimum) + minimum;
|
||||
```
|
||||
|
||||
This will produce a result that is a floating point number between two values.
|
||||
|
||||
Create a variable called `randomNum2` and assign it the result of generating a value between the `min` and `max` values.
|
||||
|
||||
Then, log the `randomNum2` variable to see the result. Try refreshing the page to see different results.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `randomNum2`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(randomNum2);
|
||||
```
|
||||
|
||||
Your `randomNum2` variable should be a number.
|
||||
|
||||
```js
|
||||
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.
|
||||
|
||||
```js
|
||||
assert.isAtLeast(randomNum2, min);
|
||||
assert.isAtMost(randomNum2, max);
|
||||
|
||||
assert.notMatch(code, /randomNum2\s*=\s*0\.\d+;?/);
|
||||
|
||||
// check for whole random numbers just in case a camper does this
|
||||
assert.notMatch(code, /randomNum2\s*=\s*\d+;?/);
|
||||
```
|
||||
|
||||
You should log the `randomNum2` variable to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*randomNum2\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 between 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;
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
---
|
||||
id: 66ea89c25e1bd871688eba6a
|
||||
title: Step 6
|
||||
challengeType: 1
|
||||
dashedName: step-6
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Up until this point, you have only been dealing with floating point numbers and the number `0`.
|
||||
|
||||
For the next part of the workshop, you will review how to work with the `Math.floor()` method.
|
||||
|
||||
Start by adding a `console.log()` that logs the message `"The Math.floor() method rounds the value down to the nearest whole integer."`
|
||||
|
||||
# --hints--
|
||||
|
||||
You should log the message `"The Math.floor() method rounds the value down to the nearest whole integer."`
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((["'])The\s+Math\.floor\(\)\s+method\s+rounds\s+the\s+value\s+down\s+to\s+the\s+nearest\s+whole\s+integer\.\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 between 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);
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
---
|
||||
id: 66eb3ec3b07dfe8f898646c0
|
||||
title: Step 7
|
||||
challengeType: 1
|
||||
dashedName: step-7
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
As you learned in the previous lecture videos, the `Math.floor()` method rounds the value down to the nearest whole integer.
|
||||
|
||||
```js
|
||||
const price = 10.99;
|
||||
Math.floor(price); // 10
|
||||
```
|
||||
|
||||
Create a variable called `numRoundedDown` and assign it the result of rounding the floating point number `6.7` down to the nearest whole integer.
|
||||
|
||||
Then, log the `numRoundedDown` variable to the console to see the result.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `numRoundedDown` variable.
|
||||
|
||||
```js
|
||||
assert.isNotNull(numRoundedDown);
|
||||
```
|
||||
|
||||
The `numRoundedDown` variable should be a number.
|
||||
|
||||
```js
|
||||
assert.isNumber(numRoundedDown);
|
||||
```
|
||||
|
||||
Your `numRoundedDown` variable should equal the result of rounding the floating point number `6.7` down to the nearest whole integer.
|
||||
|
||||
```js
|
||||
assert.equal(numRoundedDown, 6);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `6` for the `numRoundedDown` variable.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /numRoundedDown\s*=\s*6/);
|
||||
```
|
||||
|
||||
You should log the `numRoundedDown` variable to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*numRoundedDown\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 between 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.");
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
---
|
||||
id: 66eb480d996af5918d7c9c86
|
||||
title: Step 8
|
||||
challengeType: 1
|
||||
dashedName: step-8
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Now, it is time to review how the `Math.ceil()` method works.
|
||||
|
||||
Start by logging the string `"The Math.ceil() method rounds the value up to the nearest whole integer."` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should log the message `"The Math.ceil() method rounds the value up to the nearest whole integer."`
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((['"`])The\s+Math\.ceil\(\)\s+method\s+rounds\s+the\s+value\s+up\s+to\s+the\s+nearest\s+whole\s+integer\.\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 between 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--
|
||||
```
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
---
|
||||
id: 66eb488c0129e192542f0865
|
||||
title: Step 9
|
||||
challengeType: 1
|
||||
dashedName: step-9
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In the previous lecture videos, you learned how to work with the `Math.ceil()` method like this:
|
||||
|
||||
```js
|
||||
const price = 10.01;
|
||||
Math.ceil(price); // 11
|
||||
```
|
||||
|
||||
The `Math.ceil()` method rounds the value up to the nearest whole integer.
|
||||
|
||||
Create a variable called `numRoundedUp` and assign it the result of rounding the floating point number `3.2` up to the nearest whole integer.
|
||||
|
||||
Then, log the `numRoundedUp` variable to the console to see the result.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `numRoundedUp` variable.
|
||||
|
||||
```js
|
||||
assert.isNotNull(numRoundedUp);
|
||||
```
|
||||
|
||||
The `numRoundedUp` variable should be a number.
|
||||
|
||||
```js
|
||||
assert.isNumber(numRoundedUp);
|
||||
```
|
||||
|
||||
Your `numRoundedUp` variable should equal the result of rounding the floating point number `3.2` down to the nearest whole integer.
|
||||
|
||||
```js
|
||||
assert.equal(numRoundedUp, 4);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `4` for the `numRoundedUp` variable.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /numRoundedUp\s*=\s*4/);
|
||||
```
|
||||
|
||||
You should log the `numRoundedUp` variable to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*numRoundedUp\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
---
|
||||
id: 66eb499511810e932ca7eecc
|
||||
title: Step 10
|
||||
challengeType: 1
|
||||
dashedName: step-10
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The next portion of the workshop will review how to round numbers to the nearest whole integer.
|
||||
|
||||
Start by adding a `console.log()` that logs the message `"The Math.round() method rounds the value to the nearest whole integer."` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should log the message `"The Math.round() method rounds the value to the nearest whole integer."` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((['"])The\s+Math\.round\(\)\s+method\s+rounds\s+the\s+value\s+to\s+the\s+nearest\s+whole\s+integer\.\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
---
|
||||
id: 66ecdcf7c8d9a6f49094ffde
|
||||
title: Step 11
|
||||
challengeType: 1
|
||||
dashedName: step-11
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In the lecture videos, you learned that the `Math.round()` method rounds the value to the nearest whole integer.
|
||||
|
||||
Here are some examples:
|
||||
|
||||
```js
|
||||
Math.round(6.7); // 7
|
||||
Math.round(3.2); // 3
|
||||
```
|
||||
|
||||
This differs from the `Math.floor()` and `Math.ceil()` methods, which round down and up to the nearest whole integer, respectively.
|
||||
|
||||
Create a new variable called `numRounded` and assign the result of rounding the number `2.7`. Then, log the value of `numRounded` to the console.
|
||||
|
||||
Below that, create another new variable called `numRounded2` and assign the result of rounding the number `11.2`. Then, log the value of `numRounded2` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `numRounded`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(numRounded);
|
||||
```
|
||||
|
||||
You should assign the result of rounding the number `2.7` to the variable `numRounded`.
|
||||
|
||||
```js
|
||||
assert.equal(numRounded, 3);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `3` for the variable `numRounded`. Make sure you are using the `Math.round()` method.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /numRounded\s*=\s*3/);
|
||||
```
|
||||
|
||||
You should log the value of `numRounded` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*numRounded\s*\)/);
|
||||
```
|
||||
|
||||
You should have a variable called `numRounded2`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(numRounded2);
|
||||
```
|
||||
|
||||
You should assign the result of rounding the number `11.2` to the variable `numRounded2`.
|
||||
|
||||
```js
|
||||
assert.equal(numRounded2, 11);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `11` for the variable `numRounded2`. Make sure you are using the `Math.round()` method.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /numRounded2\s*=\s*11/);
|
||||
```
|
||||
|
||||
You should log the value of `numRounded2` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*numRounded2\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
console.log("The Math.round() method rounds the value to the nearest whole integer.");
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
---
|
||||
id: 66ece0b518f5dcf5930612ab
|
||||
title: Step 12
|
||||
challengeType: 1
|
||||
dashedName: step-12
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
For the last portion of the workshop, you will review how to get the minimum and maximum values of a set of numbers.
|
||||
|
||||
Start by adding a `console.log()` that logs the message `"The Math.max() and Math.min() methods are used to get the maximum and minimum number from a range."` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should log the message `"The Math.max() and Math.min() methods are used to get the maximum and minimum number from a range."` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((['"`])The\s+Math\.max\(\)\s+and\s+Math\.min\(\)\s+methods\s+are\s+used\s+to\s+get\s+the\s+maximum\s+and\s+minimum\s+number\s+from\s+a\s+range\.\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
console.log(
|
||||
"The Math.round() method rounds the value to the nearest whole integer."
|
||||
);
|
||||
|
||||
const numRounded = Math.round(2.7);
|
||||
console.log(numRounded);
|
||||
const numRounded2 = Math.round(11.2);
|
||||
console.log(numRounded2);
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
---
|
||||
id: 66ece147323c91f654bf8dd9
|
||||
title: Step 13
|
||||
challengeType: 1
|
||||
dashedName: step-13
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In the previous lecture videos, you learned how to get the maximum and minimum values from a range of numbers like this:
|
||||
|
||||
```js
|
||||
Math.max(1, 2, 3, 4, 5); // 5
|
||||
Math.min(1, 2, 3, 4, 5); // 1
|
||||
```
|
||||
|
||||
Create a variable called `maxNum` and assign it the result of finding the maximum number between the numbers `3, 125, 55, 24`. Then, log the value of `maxNum` to the console.
|
||||
|
||||
Below that, create a variable called `minNum` and assign it the result of finding the minimum number between the numbers `6, 90, 14, 90, 2`. Then, log the value of `minNum` to the console.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `maxNum`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(maxNum);
|
||||
```
|
||||
|
||||
Your `maxNum` variable should be assigned the result of the finding the maximum number between the numbers `3, 125, 55, 24`.
|
||||
|
||||
```js
|
||||
assert.equal(maxNum, 125);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `125` to the `maxNum` variable. Make sure to use the `Math.max()` method instead.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /maxNum\s*=\s*125/);
|
||||
```
|
||||
|
||||
You should log the value of `maxNum` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*maxNum\s*\)/);
|
||||
```
|
||||
|
||||
You should have a variable called `minNum`.
|
||||
|
||||
```js
|
||||
assert.isNotNull(minNum);
|
||||
```
|
||||
|
||||
Your `minNum` variable should be assigned the result of the finding the minimum number between the numbers `6, 90, 14, 90, 2`.
|
||||
|
||||
```js
|
||||
assert.equal(minNum, 2);
|
||||
```
|
||||
|
||||
You should not hardcode the value of `2` to the `minNum` variable. Make sure to use the `Math.min()` method instead.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /minNum\s*=\s*2/);
|
||||
```
|
||||
|
||||
You should log the value of `minNum` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*minNum\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
console.log(
|
||||
"The Math.round() method rounds the value to the nearest whole integer."
|
||||
);
|
||||
|
||||
const numRounded = Math.round(2.7);
|
||||
console.log(numRounded);
|
||||
const numRounded2 = Math.round(11.2);
|
||||
console.log(numRounded2);
|
||||
|
||||
console.log("The Math.max() and Math.min() methods are used to get the maximum and minimum number from a range.");
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
---
|
||||
id: 66ece75c0b840df77c7e20f0
|
||||
title: Step 14
|
||||
challengeType: 1
|
||||
dashedName: step-14
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
For the last step of the workshop, you will log the message `"It was fun learning about the different Math methods with you!"` to the console.
|
||||
|
||||
And with that last change, you have completed the MathBot workshop!
|
||||
|
||||
# --hints--
|
||||
|
||||
You should log the message `"It was fun learning about the different Math methods with you!"` to the console.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\((['"`])It\s+was\s+fun\s+learning\s+about\s+the\s+different\s+Math\s+methods\s+with\s+you\!\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 between 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("The Math.ceil() method rounds the value up to the nearest whole integer.");
|
||||
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
console.log(
|
||||
"The Math.round() method rounds the value to the nearest whole integer."
|
||||
);
|
||||
|
||||
const numRounded = Math.round(2.7);
|
||||
console.log(numRounded);
|
||||
const numRounded2 = Math.round(11.2);
|
||||
console.log(numRounded2);
|
||||
|
||||
console.log("The Math.max() and Math.min() methods are used to get the maximum and minimum number from a range.");
|
||||
|
||||
const maxNum = Math.max(3, 125, 55, 24);
|
||||
console.log(maxNum);
|
||||
const minNum = Math.min(6, 90, 14, 90, 2);
|
||||
console.log(minNum);
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
const botName = "MathBot";
|
||||
const greeting = `Hi there! My name is ${botName} and I want to teach you about the different Math methods in JavaScript.`;
|
||||
|
||||
console.log(greeting);
|
||||
|
||||
console.log(
|
||||
"The Math.random() method returns a pseudo random number between 0 and less than 1."
|
||||
);
|
||||
|
||||
const randomNum = Math.random();
|
||||
console.log(randomNum);
|
||||
|
||||
console.log("Now, generate a random number between two values.");
|
||||
const max = 100;
|
||||
const min = 1;
|
||||
|
||||
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(
|
||||
"The Math.ceil() method rounds the value up to the nearest whole integer."
|
||||
);
|
||||
const numRoundedUp = Math.ceil(3.2);
|
||||
console.log(numRoundedUp);
|
||||
|
||||
console.log(
|
||||
"The Math.round() method rounds the value to the nearest whole integer."
|
||||
);
|
||||
const numRounded = Math.round(2.7);
|
||||
console.log(numRounded);
|
||||
const numRounded2 = Math.round(11.2);
|
||||
console.log(numRounded2);
|
||||
|
||||
console.log(
|
||||
"The Math.max() and Math.min() methods are used to get the maximum and minimum number from a range."
|
||||
);
|
||||
const maxNum = Math.max(3, 125, 55, 24);
|
||||
console.log(maxNum);
|
||||
const minNum = Math.min(6, 90, 14, 90, 2);
|
||||
console.log(minNum);
|
||||
|
||||
console.log("It was fun learning about the different Math methods with you!");
|
||||
```
|
||||
Reference in New Issue
Block a user