Back to Freecodecamp

Step 15

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

latest3.0 KB
Original Source

--description--

In previous lessons, 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 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.");

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);
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--