Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Shunsuke Taguchi
9,380 PointsI followed teacher but my code doesn't work at all. Can someone take a look my code please?
var color = $(".selected").css("background-color");
var $canvas = ("canvas");
var context = $canvas[0].getContext("2d");
var lastEvent;
var mouseDown = false;
//When clicking on control list items
$(".controls").on("click", "li", function(){
//Deselect sibling elements
$(this).siblings().removeClass("selected");
//Select clicked elements
$(this).addClass("selected");
//cache the color
color = $(this).css("background-color");
});
//When new color is pressed
$("#revealColorSelect").click(function(){
//show color select or hide color select
changeColor();
$("#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 + ")");
}
//when color sliders change
$("input[type=range]").on("input", changeColor);
//when add color is pressed
$("#addNewColor").click(function(){
//append the color to the controls ul
var $newColor = $("<li></li>");
$newColor.css("background-color", $("#newColor").css("background-color"));
$(".controls ul").append($newColor);
//select new color
$newColor.click();
});
//On mouth events on the canvas
$canvas.mousedown(function(e){
lastEvent = e;
mouseDown = true;
}).mousemove(function(e){
//Draw lines
if(mouseDown) {
context.beginPath();
context.moveTo(lastEvent.offsetX, lastEvent.offsetY);
context.lineTo(e.offsetX, e.offsetY);
context.strokeStyle = color;
context.stroke();
lastEvent = e;
}
}).mouseup(function(){
mouseDown = false;
});
1 Answer

Steven Parker
216,148 PointsOne little typo...
You're missing a dollar-sign on line 2:
var $canvas = $("canvas");
Jacob Tollette
27,864 PointsJacob Tollette
27,864 PointsIt's always one little typo...
Shunsuke Taguchi
9,380 PointsShunsuke Taguchi
9,380 PointsThanks so much, Steven and Jacob!