A popular question on
not required- in the creation of certain popular JS applications, such as a
article, we'll learn how to output a random number that falls within the
range 1 to x, where x is any integer >1.
where 11 dictates that the random number will fall between 0-10. To increase
the range to, say, 100, simply change 11 to 101 instead.
Some of you may be curious as to why Math.floor(), instead of Math.round(), is used in the above code. While both successfully round off its containing parameter to an integer within the designated range, Math.floor does so more "evenly", so the resulting integer isn't lopsided towards either end of the number spectrum. In other words, a more random number is returned using Math.floor(). By the way, the Random Motivational script uses just the aforementioned code to randomly display a quote.