That's an amazing post, easy to follow and really constructive. Thank you for writing this, instead of just making the videos and thanks for sharing your knowledge with us
Oh hey, this is me again. Look, I did some tests, and, sometimes, instead of a 6 digits hexcode, the '#' + Math.floor(Math.random() * 16777215).toString(16); returns a 5 digits hexcode, what "breaks" the code, and give no background.
To solve this, I did the following code
function hexColorGenerator() {
var generatedColor = "";
for ( i = 0; i < 3; i++) {
var randomNumber = Math.floor(Math.random()*255);
if (randomNumber < 16) {
generatedColor = generatedColor + "0" + randomNumber.toString(16);
} else {
generatedColor = generatedColor + randomNumber.toString(16)
}
}
return (generatedColor);
Nice one! All of the projects in my tutorials are super basic and an be optimized to handle edge cases like this. Super awesome that you're doing that!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's an amazing post, easy to follow and really constructive. Thank you for writing this, instead of just making the videos and thanks for sharing your knowledge with us
Thank you so much! Hope it helps you ☺️
Oh hey, this is me again. Look, I did some tests, and, sometimes, instead of a 6 digits hexcode, the '#' + Math.floor(Math.random() * 16777215).toString(16); returns a 5 digits hexcode, what "breaks" the code, and give no background.
To solve this, I did the following code
function hexColorGenerator() {
var generatedColor = "";
}
Nice one! All of the projects in my tutorials are super basic and an be optimized to handle edge cases like this. Super awesome that you're doing that!