"The skirt that she is wearing is blue."
Translation:Der Rock, den sie trägt, ist blau.
The above sentence uses "den." But this sentence uses "der": "Er ist ein Mann, der weiß, was er will." Could someone please explain why?
This topic is about relative pronouns. These are the words like den in Duo's sentence and der in your example. The 'sub-sentence' between the commas in each example is called a relative clause.
Like the similar-looking definite articles (der/die/das/den/etc.), the relative pronoun is based on two things: gender and case. However, while the gender is drawn from the noun in the main sentence to which it refers (masculine in both these examples), the case is drawn from the function the pronoun plays in the relative clause (rather than the main sentence).
Let's look at your example first:
Er ist ein Mann, der weiß, was er will.
The der weiß bit is the relative clause. The relative pronoun here is der - it takes the masculine gender from Mann and the nominative case because it's the subject of the verb wissen in the relative clause.
Der Rock, den sie trägt, ist blau.
The den sie trägt bit is the relative clause. The relative pronoun here is den - it takes the masculine gender from Rock and the accusative case because it's the object of the verb tragen in the relative clause (with sie as the subject).
You can find and compare the full tables of definite articles and relative pronouns on Wikipedia, for example. They are identical except for the dative plural, and for genitive case. If you practice the Relative Pronouns lesson on Duolingo you will be exposed to examples of each.
Thank you...although unless I'm mistaken there's a simple pattern to use here: If "der" is used with a masculine noun before the first comma, then put "den" right after the comma. If "der" is not used with a masculine noun before the first comma, then put "der" right after the comma. Is that a workable general rule?
Not really. It's possible to create examples with every combination of gender/case in that table, so 4 varieties just for masculine nouns:
Nominative relative pronoun
Er ist der Mann, der läuft
= "...who runs"
Accusative relative pronoun
Er ist der Mann, den ich mag
= "...who I like"
Dative relative pronoun
Er ist der Mann, dem ich den Apfel gebe
= "...to whom I give the apple"
Genitive relative pronoun
Er ist der Mann, dessen Bruder ich kenne
= "...whose brother I know"
In each of these examples, the relative pronoun is masculine (always referring to der Mann in the main clause), but in a different case in the relative clause. Hopefully you can pick apart the examples I gave to understand the cases. It might help you to mentally rearrange the relative clauses in each example into 'normal' sentence order: der läuft; ich mag den; ich gebe dem den Apfel; ich kenne dessen Bruder.