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 3

When I refresh the page then click on "New Color" it doesn't show the actual RGB values. I have to move the slider

When Andrew refresh the page and click on the "New Color" button, it shows a black square (the actual sliders value 0 0 0), but when I do click on the button, it only shows a white square, I have to move on of the sliders so the color can show.

//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropriately
var color = $(".selected").css("background-color");

//When clicking on control list items
$(".controls li").click(function(){
  //Deselect sibling elements
  $(this).siblings().removeClass("selected");
  //Select clicked element
  $(this).addClass("selected");
  //cache current color
  color = $(this).css("background-color");
});


//When new color is pressed
$("#revealColorSelect").click(function(){
  //Show color select or hide the color select
  $("#colorSelect").toggle();
});



//update the new color span
function changeColor() {

  var r = $("#red").val();
  var g = $("#green").val();
  var b = $("#blue").val();

  $("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");
}

 $("input[type=range]").change(changeColor);
//When add color is pressed
  //Append the color to the controls ul
  //Select the new color

//On mouse events on the canvas
  //Draw lines

2 Answers

It looks like you're missing a call to changeColor inside your click handler for the "New color" button.

//When new color is pressed
$("#revealColorSelect").click(function() {
    //Show color select or hide the color select
    changeColor();
    $("#colorSelect").toggle();
});

Thank you!