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 Perfect

Anthony Ho
Anthony Ho
10,228 Points

I want to use the slider to change the thickness of the brush

This is what I got so far, but it doesn't work:

function changeThickness(){
var x = $("#thickness).val();

context.lineWidth = x;

}

$("input[type=range]").on("input", changeThickness);

2 Answers

Chad Dugas
PLUS
Chad Dugas
Courses Plus Student 13,304 Points

You need to do something like this:

$("#thickness").on("input", function() {
    context.lineWidth = $("#thickness").val();
});

  context.lineCap = "round"; 

And your HTML should look something like this:

<p>
    <label for="thickness">Thickness</label>
    <input id="thickness" name="thickness" type="range" min=1 max=50 value=1>
</p>

You can replace your whole function with that. Also you need to make the lineCap = "round". If you don't then the thick line you draw will be a collection of tiny lines. You can put that part anywhere in your program. It doesn't need to be inside a function or event.

Anthony Ho
Anthony Ho
10,228 Points

Thanks a lot. Right now I'm trying to change the cursor for only the rubber. Here is what I got so far:

if($(".rubber").contains("selected")){
$canvas.css({"cursor": "none"});
 $canvas.css({"cursor": "url(../img/eraser.png)"});   

}
Chad Dugas
Chad Dugas
Courses Plus Student 13,304 Points

I'm not totally sure I understand what you are trying to do, but I think you should try using the jQuery method .hasClass.

So your code would look like this:

if($(".rubber").hasClass("selected")){
    $canvas.css({"cursor": "none"});
    $canvas.css({"cursor": "url(../img/eraser.png)"});   
}

Also, I don't think you need you need to set the cursor to none, then assign it to the eraser image. You could probably omit that first line so it becomes:

if($(".rubber").hasClass("selected")){
    $canvas.css({"cursor": "url(../img/eraser.png)"});   
}
Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

"#thickness You're missing a " at the end :)

Anthony Ho
Anthony Ho
10,228 Points

still doesn't work though Please give me some hints. I appreciate it.