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 1

Uncaught ReferenceError: color is not defined... while checking on Console.

Here is the link for my Workspace: http://port-80-f4rkj1zb35.treehouse-app.com/

My code is actually fine.. The clicking event and the toggle.. But when I checked on the console and said color to see if it is working, it said: Uncaught ReferenceError: color is not defined..

I declared the color variable n my workspace.. so why is it like that? And will this kind of error causing trouble for the next steps?

my code:

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

//when clicking on the li
$(".controls li").click(function(){
  //deselect sibling elements
  $(this).siblings().removeClass("selected");
  //select clicked element
  $(this).addClass("selected");
  //cache the color
  color = $("this").css("background-color");
});

//reveal color selecter
$("#revealColorSelect").click(function(){

  changeColor();
  $("#colorSelect").toggle();

});

//color slider change

//press new color
  //append new color
function changeColor(){
  var r = $("#red").val();
  var g = $("#green").val();
  var b = $("#blue").val();

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

};

//draw on canvas on mouse events
Steven Parker
Steven Parker
231,275 Points

:x: You can't share a direct URL to your workspace, it's temporary and only exists while you are using it.
:information_source: But you can use the snapshot function in the workspace and provide the link to that.

1 Answer

Steven Parker
Steven Parker
231,275 Points

I saw that color was "undefined", but not because of a reference error. For me, it actually existed but had "undefined" as a value. This might be due to code changes you made since you made this forum posting.

But at this point, it appeared that the undefined value was a result of this line of code in the li click handler:

  color = $("this").css("background-color");

I suspect the quotes around this are a typo.

Julie Kohler
Julie Kohler
6,122 Points

My this is free of quotes and I'm getting the same error as Fatih. Any other ideas folks?

Steven Parker
Steven Parker
231,275 Points

Julie Kohler, try creating your own "get help" post, and be sure to include your code (or a snapshot) and a link to the course page.