Back to Freecodecamp

Step 3

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

latest1.4 KB
Original Source

--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 greater than or equal to 0 and less than 1.");
--fcc-editable-region--

--fcc-editable-region--