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

Code won't work

For some reason my code won't work anymore for the project. I got all the up through the point when you create a new color it selects it and appends it. My code was working fine up until that point. According to the Javascript Console it says I am missing a ) on line 39 but I can't find it. Would love an extra set of eyes.

//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes approprately

var color = $(".selected").css("background-color");

//When clicking on control list items
$(".controls li").on("click", function(){
  //deslect sibling elements
  $(this).siblings().removeClass("selected");
  //select clicked elements
  $(this).addClass("selected");

  //cache current color
  color = $(this).css("background-color");
});



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

});

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

//When color sliders change
$("input[type=range]").change(changeColor);

//when add color is pressed
$("#addNewColor").click(function(){
  //append the color to the control ul
  var $newColor = $("<li></li>");
  $newColor.css("background-color", $("#newColor").css("background-color"));
  $(".controls ul").append($newColor);
  //select the new color
  $newColor.click();
});

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

So I got rid of the error with some debugging. However, now I can't select the new colors that are appended to the controls list.

Not sure what I am doing wrong

Please, provide us with your environment (html, js, css) link via one of this great service on your choice: 1) http://codepen.io 2) http://jsfiddle.net 3) https://teamtreehouse.com/workspaces

1 Answer

Would you provide context of this script? It's not easy to get know what the problem when you see a part of code (HTML code also).

All I can see is no need to define "var color" and I would recommend to check "$("#red/green/blue").val();" and make parseInt() on it. Everything else - with treehouse workspace or codepen or jsfiddle. %)

I got it.

Thank you for the quick response.