1 00:00:05,930 --> 00:00:10,720 I hope you enjoyed this assignment and the questions that it involved. 2 00:00:10,730 --> 00:00:15,500 Each question was progressively getting more challenging than the previous one. 3 00:00:15,890 --> 00:00:21,080 So in this video, I'm going to go over the solution to each question. 4 00:00:21,470 --> 00:00:26,870 If you have any questions about my solution, please ask them in the Q&A section. 5 00:00:28,100 --> 00:00:32,090 So question one States create three variables with the names Val. 6 00:00:32,090 --> 00:00:34,070 One, Val to an answer. 7 00:00:34,130 --> 00:00:35,630 So let's go ahead and do that. 8 00:00:41,890 --> 00:00:42,130 Okay. 9 00:00:42,470 --> 00:00:45,500 So now we have our three variables. 10 00:00:46,040 --> 00:00:52,700 We want to perform a simple operation of generating the modulo four value one and value two. 11 00:00:53,360 --> 00:01:01,190 And we state that we need to assign the answer to the ants variable so we know value one is going to 12 00:01:01,190 --> 00:01:05,270 be value five and value two is two. 13 00:01:05,480 --> 00:01:14,090 And then we say, let ants hold the answer to the modulo of vowel one to vowel two. 14 00:01:15,110 --> 00:01:18,770 So I believe the answer to this is going to be one. 15 00:01:18,770 --> 00:01:23,870 So let's print this out and verify that that is correct. 16 00:01:26,840 --> 00:01:29,300 And we want to print out ants. 17 00:01:29,420 --> 00:01:33,770 So now we do cargo run and we see the answer is one. 18 00:01:33,770 --> 00:01:36,080 So we have question one complete. 19 00:01:37,750 --> 00:01:45,550 Question two is create a vector and put the values two, four, six, eight and ten inside the vector. 20 00:01:45,970 --> 00:01:52,690 So for us to do this, we can say let vec equals and then we can use the vector macro since we know 21 00:01:52,690 --> 00:02:01,120 what values we want to put in and we will put in two, four, six, eight and ten. 22 00:02:01,450 --> 00:02:04,750 So a very super easy way for us to create a vector. 23 00:02:05,980 --> 00:02:10,690 And then once we have created our vector, we want to print out the current values. 24 00:02:12,130 --> 00:02:15,460 So to print them out, we will use the print line macro, 25 00:02:22,930 --> 00:02:24,820 and now we will print out the vector. 26 00:02:24,820 --> 00:02:29,800 So let's make sure our vector printed out and we see we have two, four, six, eight and ten. 27 00:02:31,090 --> 00:02:39,280 Now we want to remove the value ten, add the value 12, and then print the vector back out to confirm 28 00:02:39,280 --> 00:02:40,240 our results. 29 00:02:40,540 --> 00:02:44,560 So to print it back out, we will copy and paste. 30 00:02:45,370 --> 00:02:48,850 And now we want to remove the value ten. 31 00:02:48,850 --> 00:02:52,570 Well, we see ten is the last value added in. 32 00:02:52,570 --> 00:02:58,390 So we can very easily remove this value by executing the pop method on it. 33 00:02:59,500 --> 00:03:05,380 And now we can add the value 12 by using the push method. 34 00:03:05,560 --> 00:03:10,630 And if we run, this cannot borrow as mutable. 35 00:03:10,630 --> 00:03:19,540 So what we need to do in order to mutate is we a.k.a change the values inside of the vector variable. 36 00:03:19,540 --> 00:03:23,290 We need to add the mutt key word to it. 37 00:03:23,740 --> 00:03:32,500 So now if we run it, we see that we have two, four, six, eight and 12, which is the desired output. 38 00:03:32,500 --> 00:03:42,010 So again, any time you want to mutate a variable or change it, you have to have the mute or mutt keyword 39 00:03:42,970 --> 00:03:43,990 added to it. 40 00:03:46,900 --> 00:03:51,910 For question three, we want to create a function called concatenate string. 41 00:03:52,780 --> 00:03:57,970 So can cat string. 42 00:04:00,720 --> 00:04:03,270 And then inside excuse me. 43 00:04:03,870 --> 00:04:08,160 And our main function, we want to create a string variable. 44 00:04:08,370 --> 00:04:19,680 So we will say let stir one equals a string from and we want the value. 45 00:04:20,100 --> 00:04:20,850 Hello. 46 00:04:22,850 --> 00:04:27,290 The function is going to take one argument that is of type string. 47 00:04:27,860 --> 00:04:34,190 So in here we'll have our vowel that is a string and we are going to return a string. 48 00:04:35,360 --> 00:04:43,940 So now we are returning a string and then inside the function we want to contact the string world to. 49 00:04:43,940 --> 00:04:44,660 Hello. 50 00:04:45,080 --> 00:04:46,970 So what we want to do. 51 00:04:47,910 --> 00:04:50,040 It's a vow. 52 00:04:51,300 --> 00:04:52,200 Plus. 53 00:04:54,990 --> 00:04:55,710 World. 54 00:04:57,330 --> 00:05:04,650 And now if we come back to Maine and we say, let ants equal. 55 00:05:05,820 --> 00:05:10,890 You can catch a string of stir one. 56 00:05:11,730 --> 00:05:22,980 And now if we print out ants again, we see that we successfully concatenated with hello world. 57 00:05:23,220 --> 00:05:31,050 And in case you might be wondering how come we were able to use ants down here and up here because we 58 00:05:31,050 --> 00:05:33,900 re initialized ants here. 59 00:05:33,900 --> 00:05:37,890 So the value up here is no longer valid. 60 00:05:37,890 --> 00:05:42,240 Ants will now only be referred to by our value down here. 61 00:05:43,470 --> 00:05:50,730 So now we have successfully created a string function that will concatenate strings together. 62 00:05:51,480 --> 00:05:57,930 And then our last question is create a function called control flow. 63 00:06:00,210 --> 00:06:03,840 So we have control flow. 64 00:06:03,840 --> 00:06:05,370 So we created our function. 65 00:06:06,060 --> 00:06:09,510 And this is going to take one argument that is an integer. 66 00:06:09,510 --> 00:06:17,880 So we will say VAO and we'll just give it IE 32 and then based on this integer, print out the following 67 00:06:17,880 --> 00:06:19,320 the value is one. 68 00:06:19,320 --> 00:06:27,600 The value is greater than 50, the value is less than 25 or the value is greater than 25, but less 69 00:06:27,600 --> 00:06:28,500 than 50. 70 00:06:30,090 --> 00:06:30,660 Okay. 71 00:06:30,990 --> 00:06:40,680 So inside of here, we want to check if Val is equal to one, then print out 72 00:06:43,500 --> 00:06:45,300 the value is one. 73 00:06:50,480 --> 00:06:52,490 And we're going to have a couple of print statements. 74 00:06:52,490 --> 00:06:54,080 So let's go ahead and do this. 75 00:06:55,030 --> 00:07:04,880 ELTs, if Val is greater than 50, print out. 76 00:07:05,450 --> 00:07:10,100 The value is greater than 50. 77 00:07:11,480 --> 00:07:14,600 Else if the val is. 78 00:07:15,720 --> 00:07:18,600 Less than 25. 79 00:07:19,560 --> 00:07:21,240 We want to print out 80 00:07:24,620 --> 00:07:28,920 the value is less than 25. 81 00:07:32,710 --> 00:07:33,550 Else. 82 00:07:35,960 --> 00:07:47,360 Print out the value is greater than 25, but less than 50. 83 00:07:50,200 --> 00:08:01,930 So now if we call this function control flow, let's pass in the value five and let's see what is returned. 84 00:08:03,330 --> 00:08:05,310 The value is less than 25. 85 00:08:05,850 --> 00:08:06,940 That is correct. 86 00:08:06,960 --> 00:08:09,300 If we pass in 500. 87 00:08:10,840 --> 00:08:12,880 The value is greater than 50. 88 00:08:13,030 --> 00:08:14,530 That is correct. 89 00:08:14,980 --> 00:08:16,270 If we pass in one. 90 00:08:18,220 --> 00:08:19,520 Value is one. 91 00:08:19,540 --> 00:08:20,920 That is correct. 92 00:08:21,960 --> 00:08:27,940 If we pass in 25, the value is greater than 25, but less than 50. 93 00:08:28,060 --> 00:08:32,140 And that is also correct, because we did not use an equal sign here. 94 00:08:34,150 --> 00:08:34,830 Or here. 95 00:08:34,840 --> 00:08:38,140 So now if we run this, we will see. 96 00:08:39,260 --> 00:08:44,870 Value is less than 25 because now we are also including the value 25. 97 00:08:45,870 --> 00:08:52,110 So hopefully you were able to understand and accomplish these questions with ease. 98 00:08:52,110 --> 00:08:57,990 And if you were, then you are definitely ready to move on to the next section where we begin talking 99 00:08:57,990 --> 00:08:59,520 about ownership.