INSTRUCTOR: The next function that we're asking you to implement is duration.
Let's take a look at what you're going to need to do for that now.
Let's first take a look at the signature for duration.
Duration is a function that takes a fraction that's
represented as a string as its input and outputs an int.
And effectively, what we'll be asking you to do is take in that fraction
as a string, where that fraction is going to look like something like 1/8
for one eighth, or 1/4, or 3/8, and you can
assume that the numerator and denominator will each be one digit,
and based on that, your goal is to return to the user
the number of eighth notes long that the note is going to last.
So if the input for example is one slash eight, or one eighth,
that is one eighth note, and so your function would return the number one.
Meanwhile, if the input were one slash four, well
that's two eighth notes, because it's one quarter, which is twice one eighth.
And so your function would return two.
And likewise, if the input were three slash eight, or three over eight, then
your output is three, because that's equivalent to three eighth notes.
And so your goal here is to take this text-based representation
of the duration of a note and turn it into how many eighth notes long
that note should actually last.
And you can assume that the fraction will work out
to a whole number of eighth notes, so that your return type can indeed
be an integer.
How much you go about thinking about this,
well, think about what the possible values for the denominator could be.
It could be over eight, or over four, or over two, or even over one.
And based on that, you know that if the numerator and denominator are each one
digit long, and they have a slash in between them,
you can figure out that, OK, the first character of that string
is going to be the numerator, and the last character of that string
is going to be the denominator.
And now, if you know where the numerator and denominator are in the string,
and you know what the possible values for that denominator are,
you should be able to figure out how to do the math in order
to take that string-based representation and convert it
into a number of eighth notes.
But do be careful.
If you just extract the first character of the string,
remember that what you'll get is not the number of the numerator,
but a character representing the number of a numerator.
So think about how you might be able to convert that character
into an actual number, for instance.
But once you do that, you should well on your way to figuring out duration.