1
00:00:00,520 --> 00:00:05,500
So as we're generating out the enemies, we can also generate a random color, so we're going to add

2
00:00:05,500 --> 00:00:08,280
in a function that's going to generate that random color.

3
00:00:08,470 --> 00:00:14,580
We can just call it random color and we want to return back random hex values.

4
00:00:14,580 --> 00:00:15,670
So we're returning back.

5
00:00:16,240 --> 00:00:22,470
And with Hex, we need to do the hash in front of it for the color and we're going to run several functions.

6
00:00:22,840 --> 00:00:30,030
So integrate these functions that are generated out the value of a random hex value.

7
00:00:30,850 --> 00:00:31,990
So creating a function.

8
00:00:33,120 --> 00:00:38,580
We can call it function C. We only need it to use it within the random color and we're going to call

9
00:00:38,580 --> 00:00:40,170
to this value.

10
00:00:40,470 --> 00:00:49,950
So creating out our hex value, using math, math, random, and you'll see that online there's several

11
00:00:49,950 --> 00:00:54,250
different ways and there's actually some shorter ones as well to generate random colors.

12
00:00:54,780 --> 00:00:56,720
This one's a little bit easier to explain.

13
00:00:57,270 --> 00:01:03,940
So we see that we're generating a random number from zero to 255 and we know all of those digits.

14
00:01:03,960 --> 00:01:07,380
So if we do in our job color that it's going to be zero to 255.

15
00:01:07,680 --> 00:01:12,670
And what we want to do is transform this to a string value, to a hex value.

16
00:01:12,960 --> 00:01:16,040
And the way that we do that is we do to string 16.

17
00:01:16,320 --> 00:01:20,730
So that's going to convert our decimal number to a hex number returning back.

18
00:01:20,740 --> 00:01:24,760
And as we know, with colors, we get FFE and so on.

19
00:01:24,900 --> 00:01:30,890
So those give us that 255 zero to 255 in a string value.

20
00:01:31,080 --> 00:01:36,360
And there's one other thing that we do need to take care of before we return this value.

21
00:01:36,540 --> 00:01:44,910
And that's in case we end up with only a one digit number within our hex value for the colors, we're

22
00:01:44,910 --> 00:01:47,020
going to need all six characters.

23
00:01:47,340 --> 00:01:54,630
So this is to make sure that in case our hex value turns out to be only one character, we're going

24
00:01:54,630 --> 00:01:58,590
to use a substring value of minus two.

25
00:01:58,830 --> 00:02:05,160
And you can use this for numbers as well to make sure that you do get instead of if you go down under

26
00:02:05,160 --> 00:02:06,870
10, you're only going to have one digit there.

27
00:02:06,870 --> 00:02:09,250
If you want to digits, then you can do this as well.

28
00:02:09,450 --> 00:02:16,100
So this will always make sure that you're returning back a value of at least two characters, two digits.

29
00:02:16,440 --> 00:02:19,290
So we've got our zero that we're placing in front of it.

30
00:02:19,440 --> 00:02:26,220
And if we need to use it, so zero plus the string value of hex, which is this one we've generated

31
00:02:26,220 --> 00:02:26,750
up here.

32
00:02:26,970 --> 00:02:31,950
And if this one is two characters, then it's only going to return back the last two characters.

33
00:02:32,220 --> 00:02:37,560
If it's one character, then it's going to still return back the last two characters, but we're dropping

34
00:02:37,560 --> 00:02:38,690
a zero in front of it.

35
00:02:39,030 --> 00:02:44,970
So now that we've generated a random color, we can update this value to be random colors.

36
00:02:45,180 --> 00:02:50,120
And you'll see that now we're generating random colors for those enemy cars.

37
00:02:50,760 --> 00:02:57,940
Also, we need to apply that into where we're generating the items as well.

38
00:02:57,960 --> 00:03:02,020
So whenever they run off of the page and this is another one of those optional things.

39
00:03:02,040 --> 00:03:06,140
So if it runs off the page, we can generate a random color for it.

40
00:03:06,390 --> 00:03:08,640
So assigning a different color value to it.

41
00:03:08,820 --> 00:03:13,560
And again, this is another one of those optional things that we don't have to add, but we can add

42
00:03:13,560 --> 00:03:14,250
if we want to.

43
00:03:14,250 --> 00:03:20,130
Of course, also within the enemy, you can add in value in the inner.

44
00:03:21,200 --> 00:03:25,230
HTML, and you can set a value of X if you want it to.

45
00:03:25,250 --> 00:03:29,750
So we could do X plus one so we know what car number it is.

46
00:03:30,140 --> 00:03:36,290
And then going back into here, if we have any text in here, we can make this really big so we can

47
00:03:36,290 --> 00:03:48,910
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.

48
00:03:49,100 --> 00:03:51,550
We don't need to to write car on it, of course.

49
00:03:51,830 --> 00:03:58,130
So as we generate this out, we can get rid of this line here that's writing out the inner text for

50
00:03:58,130 --> 00:03:59,200
that for our.

51
00:03:59,330 --> 00:04:03,110
So you can see now we've got the cars, they're going to have numbers on them.

52
00:04:03,110 --> 00:04:07,310
So one, two, three, and then we're going to have one coming back and so on.

53
00:04:07,940 --> 00:04:15,170
So going back, let's also or we'll do a text align and center text and also vertical line.

54
00:04:16,250 --> 00:04:17,300
So line it to the middle.

55
00:04:18,170 --> 00:04:23,220
Cecille, that looks and if we want it to as well, we could add in a space there.

56
00:04:23,270 --> 00:04:24,130
So a line break.

57
00:04:24,470 --> 00:04:29,080
So where we've got that inner HTML because it is HTML of course.

58
00:04:29,630 --> 00:04:31,470
So that will move it down one.

59
00:04:31,550 --> 00:04:36,800
So let's try the game out and we'll work through any of the final bugs that we have within the game

60
00:04:36,800 --> 00:04:39,200
and the application in the upcoming lesson.

61
00:04:40,440 --> 00:04:45,690
So that's still to come as well as we can make them look a little bit more like cars as well within

62
00:04:45,690 --> 00:04:47,100
the car, if one or two.
