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

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 5

nishnash
nishnash
6,267 Points

Color does not change when selected

Hi,

Ahhh, i know i'm missing something but cannot figure it out...

When i open, i am able to draw the color red. However when i switch colors to blue or green, it still colors it in red...

On line 60, i changed color to $color and it worked..(but now the red is not selected by default and i cannot draw until i switch the color. When i switch once, i am able to go back and color using all colors... )

https://w.trhou.se/fjmakkcagd

3 Answers

Steven Parker
Steven Parker
231,275 Points

:point_right: There is no $color variable in this program.

You don't want to change line 60. But on line 17, where you have $color, it should just be color.

If you had been using JavaScript's "strict mode", assigning an undeclared variable would have generated an error.

nishnash
nishnash
6,267 Points

Awesome. Thanks again for your help Steven... :)

Rebecca Jensen
Rebecca Jensen
11,580 Points

I had a similar problem, but what it took to fix mine was changing all my const's to var's. Andrew uses var in the video, but I was trying to use the new standard of using either 'const' or 'let' instead of 'var'.

Really, I should have spent time figuring out which var should be const and which should be let, but changing all to var was the quicker fix.

This doesn't solve your problem (and it sounds like yours is already solved!), but I thought I'd leave this here for others facing a similar issue.

Const is meant for variables that aren't going to be changed, let is for variables that will be changed, and var can be used either way. I believe the current practice is to choose either const or let.