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

Janneke Polderman
Janneke Polderman
7,157 Points

Why did my .toggle stop working after I added the changeColor function?

After I added the changeColor function I cannot use the New Color button anymore. Why? Is there something wrong with the code?

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

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

Later on I saw that Toggle is predecated. What else can you use instead of this?

2 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

All your variables are named var r but they should be different

//update the new color span 
function changeColor() { 
  var r = $ ("#red").val(); 
  var r = $ ("#green").val(); // should be var g
  var r = $ ("#blue").val(); // should be var b
  $("#newColor").css("background-color", "rgb(" + r + "," + g + ", " + b + " )"); 
}

Your variables are the same "r"

Changed this:

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

to this:

//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 + " )"); }