1 00:00:00,000 --> 00:00:00,402 2 00:00:00,402 --> 00:00:03,610 INSTRUCTOR: The next function that we're asking you to implement is duration. 3 00:00:03,610 --> 00:00:06,430 Let's take a look at what you're going to need to do for that now. 4 00:00:06,430 --> 00:00:09,190 Let's first take a look at the signature for duration. 5 00:00:09,190 --> 00:00:11,800 Duration is a function that takes a fraction that's 6 00:00:11,800 --> 00:00:16,320 represented as a string as its input and outputs an int. 7 00:00:16,320 --> 00:00:19,690 And effectively, what we'll be asking you to do is take in that fraction 8 00:00:19,690 --> 00:00:24,220 as a string, where that fraction is going to look like something like 1/8 9 00:00:24,220 --> 00:00:28,000 for one eighth, or 1/4, or 3/8, and you can 10 00:00:28,000 --> 00:00:31,720 assume that the numerator and denominator will each be one digit, 11 00:00:31,720 --> 00:00:34,870 and based on that, your goal is to return to the user 12 00:00:34,870 --> 00:00:38,980 the number of eighth notes long that the note is going to last. 13 00:00:38,980 --> 00:00:43,010 So if the input for example is one slash eight, or one eighth, 14 00:00:43,010 --> 00:00:47,800 that is one eighth note, and so your function would return the number one. 15 00:00:47,800 --> 00:00:51,670 Meanwhile, if the input were one slash four, well 16 00:00:51,670 --> 00:00:56,050 that's two eighth notes, because it's one quarter, which is twice one eighth. 17 00:00:56,050 --> 00:00:58,450 And so your function would return two. 18 00:00:58,450 --> 00:01:02,560 And likewise, if the input were three slash eight, or three over eight, then 19 00:01:02,560 --> 00:01:06,860 your output is three, because that's equivalent to three eighth notes. 20 00:01:06,860 --> 00:01:09,940 And so your goal here is to take this text-based representation 21 00:01:09,940 --> 00:01:13,420 of the duration of a note and turn it into how many eighth notes long 22 00:01:13,420 --> 00:01:15,370 that note should actually last. 23 00:01:15,370 --> 00:01:17,470 And you can assume that the fraction will work out 24 00:01:17,470 --> 00:01:21,310 to a whole number of eighth notes, so that your return type can indeed 25 00:01:21,310 --> 00:01:22,380 be an integer. 26 00:01:22,380 --> 00:01:24,130 How much you go about thinking about this, 27 00:01:24,130 --> 00:01:27,640 well, think about what the possible values for the denominator could be. 28 00:01:27,640 --> 00:01:32,920 It could be over eight, or over four, or over two, or even over one. 29 00:01:32,920 --> 00:01:37,690 And based on that, you know that if the numerator and denominator are each one 30 00:01:37,690 --> 00:01:40,720 digit long, and they have a slash in between them, 31 00:01:40,720 --> 00:01:44,110 you can figure out that, OK, the first character of that string 32 00:01:44,110 --> 00:01:47,620 is going to be the numerator, and the last character of that string 33 00:01:47,620 --> 00:01:49,550 is going to be the denominator. 34 00:01:49,550 --> 00:01:52,930 And now, if you know where the numerator and denominator are in the string, 35 00:01:52,930 --> 00:01:56,320 and you know what the possible values for that denominator are, 36 00:01:56,320 --> 00:01:59,260 you should be able to figure out how to do the math in order 37 00:01:59,260 --> 00:02:02,590 to take that string-based representation and convert it 38 00:02:02,590 --> 00:02:04,120 into a number of eighth notes. 39 00:02:04,120 --> 00:02:05,710 But do be careful. 40 00:02:05,710 --> 00:02:08,310 If you just extract the first character of the string, 41 00:02:08,310 --> 00:02:11,260 remember that what you'll get is not the number of the numerator, 42 00:02:11,260 --> 00:02:14,230 but a character representing the number of a numerator. 43 00:02:14,230 --> 00:02:17,230 So think about how you might be able to convert that character 44 00:02:17,230 --> 00:02:19,870 into an actual number, for instance. 45 00:02:19,870 --> 00:02:24,540 But once you do that, you should well on your way to figuring out duration. 46 00:02:24,540 --> 00:02:26,091