Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialColin Hartmann
Courses Plus Student 2,875 PointsWhy Math.random doesn't have any input in the function parentheses
In the code solution, for my code, I put the user's input within the Math.random() parentheses (so it would look like Math.random(/user input/)
Why do you not put the user's input within the Math.random function?
1 Answer
Samuel Webb
25,370 PointsBecause Math.random()
doesn't need an argument. What you'd want to do is Math.random * userInput
. Math.random()
returns a random number between 0 and 1. So you want to multiplay it by whatever the user's input is. You could also do Math.floor(Math.random() * userInput)
or `Math.ceil(Math.random() * userInput)' to get a whole number (integer).
Colin Hartmann
Courses Plus Student 2,875 PointsColin Hartmann
Courses Plus Student 2,875 PointsWhat would the code be saying if I typed Math.random(userInput)?
Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsIt won't say anything. It'll just give you the random number it would have given you regardless.
Colin Hartmann
Courses Plus Student 2,875 PointsColin Hartmann
Courses Plus Student 2,875 PointsOk thx
Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsTo learn more about Math in JS, check out the Documentation Here