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

CSS Flask Basics Character Builder Items

If statement

Hi,

I am struggling to understand what is going on in this line of code:

{% if saves.get(category) == choice %} checked {% endif %}

Why would the if statement check if what has been saved is equal to choice? In that regard, how do we make sure that it will check the item that we have selected and not other?

Thanks for your help?

1 Answer

Daniel Schirmer
Daniel Schirmer
4,364 Points

It's not totally clear, because I couldn't see the code for the Update button, but the Update button should save the item that is clicked into the cookie. saves.get(category). So I think it would go like:

  1. User clicks an item picture in a category and then clicks Update
  2. Update button saves the item name/category into a cookie (via the save function with url redirects)
  3. The if statement in question checks the cookie for a match {'shorts': 'yellow'} and makes "checked" the value from the key-value pair in the cookie.