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 2

Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Color doesn't show in new color selector

I've read over my code again and again but I can't figure out why the colored square doesn't show up when I click on the New Color button. I'm using Safari FYI.

Here is a link to the code: https://w.trhou.se/85bxjtyejw

1 Answer

Hey Nathan,

You just had a minor problem in your code. In the line that set your background color in the changeColor function, background was spelled as "backgroud".

I would also recommend changing your slider action to an "on" event handler and using "input" as the event, because you'll see the colors change as you drag the slider, instead of only when you let go :P

function changeColor() { 
  var r = $("#red").val();
  var g = $("#green").val();
  var b = $("#blue").val();
  //Changed backgroud to background
  $("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");
}

//When color sliders change
//changed to "on" handler with "input" as the event
//can watch colors change as you slide now :)
$("input[type=range]").on("input", changeColor);
Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Gah! Darn typos get me every time. You're a champion Marcus!

Haha I know what you mean! :P Good luck, Nathan!

Btw, since I solved your problem (and gave you a cool event handler), you could possibly mark my answer as best answer! :)

Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Done and done. Thanks again! Here's to better debugging skills as I learn.

Not a problem! Everyone needs someone else to look over their work at some point or another. I don't think it's at all that your debugging skills are lacking or anything of the sort; I think that spelling errors like this are one of those little things you don't think to check because you're too busy thinking about what could be wrong with the logic of the code haha I do the exact same thing sometimes. Looking at miles of code has taught me to look at every single thing though :P