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 4

Santiago Enciso
Santiago Enciso
17,789 Points

beginPath() not working

var context = $("canvas")[0].getContext("2nd");

context.beginPath(); context.moveTo(10, 10); context.lineTo(20, 10); context.lineTo(20, 20); context.lineTo(10, 20); context.closePath() context.stroke

When I inspect the element in the JS Console, it says "Uncaught TypeError: context.beginPath in not a function"

Please help

3 Answers

You are trying to get "2nd" for your context instead of "2d".

Try

var context = $("canvas")[0].getContext("2d");

I was having the same problem because I had the same mistake!

Were you able to get it working?

Yes, once I realized the mistake, it worked like a charm!