Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Malcolm Robertson
Malcolm Robertson
8,478 Points

reverse-text-filter

I am stuck on https://teamtreehouse.com/library/customizing-django-templates/building-custom-filters/reverse-text-filter

I have entered :

from django import template

register = template.Library()

def reverse_text(text):
    my_string = "balloon"
    text = my_string[::-1]

    return text

Which I believe to be correct but I am getting:

Bummer! The reverse_text function isn't returning the string we expected. Try this: text_to_reverse[::-1])

What am I missing?

1 Answer

It doesn't want you to make your own variable for the string. This will be provided as the argument for your 'text' parameter. You pretty much had it right, you just needed to use the argument that is passed to the function and return the reverse of that argument. Here is the code:

from django import template

register = template.Library()

def reverse_text(string_argument):
    return string_argument[::-1]
Malcolm Robertson
Malcolm Robertson
8,478 Points

Thanks that was driving me crazy.