Skip to content
Discussion options

You must be logged in to vote

Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
Multiplying by hex_numbers.length (which is 15) scales this random number to the range of the array indices.
Math.floor() rounds down to the nearest integer, giving a valid index for the array.

This loop will iterate 6 times, appending a random number from hex_numbers randomly each time. At the end of the loop hexcode will be a string with 6 numbers corresponding to the 6 characters in a hexadecimal color code (e.g. #RRGGBB).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MayoioI
Comment options

Answer selected by MayoioI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pull Requests Propose, review, and discuss changes to a repository's codebase Show & Tell Discussions where community members share their projects, experiments, or accomplishments
2 participants