1 00:00:00,550 --> 00:00:05,770 The solution is going to cover tasks nine and 10 from your final challenge, Task nine tells us to check 2 00:00:05,770 --> 00:00:07,780 the left diagonal for a straight Exaro. 3 00:00:13,490 --> 00:00:15,890 The first and second inducts are always consistent. 4 00:00:16,219 --> 00:00:18,800 They both start at zero and go up until two. 5 00:00:27,000 --> 00:00:29,700 So we can make a for loop or the counter starts at zero. 6 00:00:34,910 --> 00:00:36,110 Goes up until two. 7 00:00:50,860 --> 00:00:54,700 And we can use a single counter to index the ROE and the elements. 8 00:00:56,600 --> 00:01:02,150 Ultimately, this is going to run through every value in the left diagonal, zero zero one one and two 9 00:01:02,150 --> 00:01:02,450 to. 10 00:01:10,630 --> 00:01:14,620 And we can apply the same logic if it's a tax, increase it by one. 11 00:01:20,670 --> 00:01:23,010 If it's a no decrease the counter by one. 12 00:01:39,530 --> 00:01:44,360 And after this loop runs, we know that we've just checked every value in the left diagonal. 13 00:01:45,360 --> 00:01:48,660 If the left diagonal has straight axis or Stratos. 14 00:01:57,100 --> 00:01:58,210 Return the counts. 15 00:02:03,170 --> 00:02:05,570 Otherwise, reset the count to zero. 16 00:02:09,560 --> 00:02:13,640 Now, you might be thinking the loop only runs once, why are we resetting the count to zero? 17 00:02:14,240 --> 00:02:18,890 Well, we still need to check the right diagonal and we want to make sure the count is that zero when 18 00:02:18,890 --> 00:02:19,610 we're doing that. 19 00:02:22,080 --> 00:02:25,410 But before we move on to Task 10, let's run a quick test. 20 00:02:55,220 --> 00:02:56,900 And perfect sex wins. 21 00:02:58,990 --> 00:03:03,640 As I played the sax during this turn, the check win function was called. 22 00:03:07,080 --> 00:03:09,810 None of the roads contained a straight Exaro. 23 00:03:13,990 --> 00:03:16,810 None of the columns contain a straight zero. 24 00:03:21,410 --> 00:03:25,430 This loop ran through the left diagonal, it counted straight axis. 25 00:03:28,300 --> 00:03:31,360 Returned a count of three, which means ACSA wins. 26 00:03:32,860 --> 00:03:35,680 All right, we can try testing a scenario where Erwin's. 27 00:03:55,060 --> 00:03:57,940 Nice owns everything, works well. 28 00:04:06,990 --> 00:04:13,530 And now for the final task, if none of the rows, columns or left diagonal result in a win, we need 29 00:04:13,530 --> 00:04:16,390 to check the right diagonal for a straight arrow. 30 00:04:16,950 --> 00:04:18,149 This one is kind of tricky. 31 00:04:21,000 --> 00:04:25,140 Looking at the gif, the first index is two one zero. 32 00:04:26,940 --> 00:04:29,430 And the second index is zero one and two. 33 00:04:32,400 --> 00:04:38,010 And with this hint, I was trying to tell you to make a loop or the counter starts from zero and goes 34 00:04:38,010 --> 00:04:38,850 up until two. 35 00:04:42,310 --> 00:04:46,720 And during each year on set, the Roman ducks equal to two minus that counter. 36 00:04:54,060 --> 00:04:57,750 And we can do just that, create a loop that runs from I equals zero. 37 00:05:01,660 --> 00:05:03,850 I smaller than three iReports plus. 38 00:05:08,020 --> 00:05:11,740 Will set int Roe index is equal to two minus I. 39 00:05:15,340 --> 00:05:18,190 And we can use these two values to index our board. 40 00:05:27,290 --> 00:05:32,180 It follows that during the first run, the role will be to add the element at that index is going to 41 00:05:32,180 --> 00:05:38,600 be zero in the second run, both indexes are going to be won and in the third run, the road will be 42 00:05:38,600 --> 00:05:39,010 zero. 43 00:05:39,020 --> 00:05:40,430 And the element is going to be to. 44 00:05:41,450 --> 00:05:45,620 All right, as we go through the right diagonal, we're going to check if the values in X. 45 00:05:49,710 --> 00:05:52,170 In which case, update the counter by one. 46 00:06:00,180 --> 00:06:02,970 Otherwise, decrease the counter by one. 47 00:06:16,130 --> 00:06:19,100 All right, and we've reached the end of our function. 48 00:06:21,550 --> 00:06:22,560 Let's test it out. 49 00:06:46,210 --> 00:06:51,250 Woops, I meant to put a zero to end with this final pay X wins. 50 00:06:56,020 --> 00:06:58,360 During this turn, none of the rose. 51 00:07:00,140 --> 00:07:00,860 Columns. 52 00:07:01,820 --> 00:07:04,040 Or left diagonal resulted in a win. 53 00:07:06,490 --> 00:07:11,620 So we reached the final loop, which counts the number of Accessor O's in the right diagonal and returns 54 00:07:11,620 --> 00:07:12,190 the count. 55 00:07:15,180 --> 00:07:18,030 That value ended up being three, so X wins. 56 00:07:20,690 --> 00:07:22,520 Let's test a case of Erwin's. 57 00:07:52,950 --> 00:07:54,610 And our app is bulletproof. 58 00:07:55,800 --> 00:08:00,120 Now, what if there is a tie, given the current state of our code, what would happen? 59 00:08:00,500 --> 00:08:01,250 Let's find out. 60 00:08:15,640 --> 00:08:22,570 And as you might expect, nothing we've exhausted all night turns without Stridex Zorro's, but it would 61 00:08:22,570 --> 00:08:24,910 be nice to print something like it's a tie. 62 00:08:27,380 --> 00:08:33,770 So here, if there aren't any street axes or stray dogs and it's the very last run, then we need to 63 00:08:33,770 --> 00:08:34,730 print it to tie. 64 00:08:36,220 --> 00:08:37,270 So if. 65 00:08:42,179 --> 00:08:46,500 I equals eight if it's the last turn that was taken and nobody won. 66 00:08:50,370 --> 00:08:52,020 Then we'll print it's a tie. 67 00:08:57,390 --> 00:08:58,800 Let's do one final test. 68 00:09:27,730 --> 00:09:33,520 And with this, I am proud to announce that you have now officially completed Module one, you have 69 00:09:33,520 --> 00:09:36,310 my sincere congratulations for making it this far. 70 00:09:37,240 --> 00:09:41,950 Now you know how to use variables to store information, use a false and switch to control how your 71 00:09:41,950 --> 00:09:49,060 code runs or organize your code into functions that perform tasks, run your code in a loop and use 72 00:09:49,060 --> 00:09:51,820 arrays to work with many values at once.