what is the purpose of 了 in this sentence ?
Be careful. Many speakers of European languages often equate 了 with past tense. While It can be translated that way, that's not what 了 really is. Rather than tense, it represents aspect, in this case a completed aspect of the verb. Remember that Chinese has no tense. A lot of European language speakers, when starting out speaking Chinese, tend to add 了 wherever they would use past tense in their native languages, and it makes their Chinese sound very unnatural.
The use of 了 is quite complicated. If you're interested in an article which tries to explain it, it's here: https://www.chineseboost.com/grammar/le-grammar-summary/
That being said, I still don't quite get it, and I'm not sure that Duolingo is the best place to clarify it completely.