Learn JavaScript: 6. Random HELP


#1


https://www.codecademy.com/courses/learn-javascript/lessons/introduction-to-javascript/exercises/random?action=lesson_resume


It keeps saying 'Expected an assignment or function call and instead saw an expression'
I even followed the hint exactly and it still isn't letting me through.


Math.random() * 100


#2

@handstogether2000

just follow the instructions!

First Step:

"1. Inside of a console.log, create a random number with Math.random, then multiply it by 100.
If you run the program few times, you'll see random numbers in the console."

console.log(Math.random() * 100);

Second Step:

"Now, utilize Math.floor to make the output a whole number.
Inside the console.log you wrote in the last step, put Math.random() * 100 inside the parentheses of Math.floor."

console.log(Math.floor(Math.random() * 100));

And your problem is solved!

Please note the following:

  • Do not forget the semicolons!

  • The Math.random() function returns a floating-point, pseudo-random number in the range [0, 1) that is, from 0 (inclusive) up to but not including 1 (exclusive), which you can then scale to your desired range.

  • The Math.floor() function returns the largest integer less than or equal to a given number.


Inside of a console.log, create a random number with Math.random, then multiply it by 100. If you run the program few times, you'll see random numbers in the console
#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.