Back to Freecodecamp

Step 5

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

latest1.7 KB
Original Source

--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 formula 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 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;
--fcc-editable-region--

--fcc-editable-region--