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 trialVivek Reddy
Courses Plus Student 5,486 Pointsonce I open the options menu and un-check a color (eg: red), what would happen if we re-check the item?
How to include the functionality to toggle a particular menu Item? If I un-check the red menu item, the picture loses the red, but if I re-check it, will it get the red color back on? Where can we include that code?
1 Answer
Seth Kroger
56,413 PointsThe code from the video should do that already. You'll notice the line red = !red;
that is executed whenever the item is selected. It means "Give red
the value of NOT-red
". This will invert the current state of the red
option, ie., from true to false or from false to true.
Vivek Reddy
Courses Plus Student 5,486 PointsVivek Reddy
Courses Plus Student 5,486 PointsThanks a lot :), I saw the red = !red as, removing the red color. When it actually was variable toggling the value. My bad.