So as we're generating out the enemies, we can also generate a random color, so we're going to add
in a function that's going to generate that random color.
We can just call it random color and we want to return back random hex values.
So we're returning back.
And with Hex, we need to do the hash in front of it for the color and we're going to run several functions.
So integrate these functions that are generated out the value of a random hex value.
So creating a function.
We can call it function C. We only need it to use it within the random color and we're going to call
to this value.
So creating out our hex value, using math, math, random, and you'll see that online there's several
different ways and there's actually some shorter ones as well to generate random colors.
This one's a little bit easier to explain.
So we see that we're generating a random number from zero to 255 and we know all of those digits.
So if we do in our job color that it's going to be zero to 255.
And what we want to do is transform this to a string value, to a hex value.
And the way that we do that is we do to string 16.
So that's going to convert our decimal number to a hex number returning back.
And as we know, with colors, we get FFE and so on.
So those give us that 255 zero to 255 in a string value.
And there's one other thing that we do need to take care of before we return this value.
And that's in case we end up with only a one digit number within our hex value for the colors, we're
going to need all six characters.
So this is to make sure that in case our hex value turns out to be only one character, we're going
to use a substring value of minus two.
And you can use this for numbers as well to make sure that you do get instead of if you go down under
10, you're only going to have one digit there.
If you want to digits, then you can do this as well.
So this will always make sure that you're returning back a value of at least two characters, two digits.
So we've got our zero that we're placing in front of it.
And if we need to use it, so zero plus the string value of hex, which is this one we've generated
up here.
And if this one is two characters, then it's only going to return back the last two characters.
If it's one character, then it's going to still return back the last two characters, but we're dropping
a zero in front of it.
So now that we've generated a random color, we can update this value to be random colors.
And you'll see that now we're generating random colors for those enemy cars.
Also, we need to apply that into where we're generating the items as well.
So whenever they run off of the page and this is another one of those optional things.
So if it runs off the page, we can generate a random color for it.
So assigning a different color value to it.
And again, this is another one of those optional things that we don't have to add, but we can add
if we want to.
Of course, also within the enemy, you can add in value in the inner.
HTML, and you can set a value of X if you want it to.
So we could do X plus one so we know what car number it is.
And then going back into here, if we have any text in here, we can make this really big so we can
do font size and set that to be to M and also get rid of that name car as we're generating out our car.
We don't need to to write car on it, of course.
So as we generate this out, we can get rid of this line here that's writing out the inner text for
that for our.
So you can see now we've got the cars, they're going to have numbers on them.
So one, two, three, and then we're going to have one coming back and so on.
So going back, let's also or we'll do a text align and center text and also vertical line.
So line it to the middle.
Cecille, that looks and if we want it to as well, we could add in a space there.
So a line break.
So where we've got that inner HTML because it is HTML of course.
So that will move it down one.
So let's try the game out and we'll work through any of the final bugs that we have within the game
and the application in the upcoming lesson.
So that's still to come as well as we can make them look a little bit more like cars as well within
the car, if one or two.