Ask coding questions

← Back to all posts
how do i draw a circle or a square in java script?

I write rect(200,200,200,200); for square because khan academy told me to do it like that but it says i have to describe it? I don't know how to though. does anyone know how to describe shapes in javascript?


Although I am very rusty with js, I'm pretty sure you need to define the unit. For example, 200px 200px. I'm also not entirely sure you need 4 values. BTW, in your repl, it says 200 200 300 350, meaning it's literally not a rectangle. What purpose would you need a js rectangle for?
P.S. ka uses processingjs and not regular js in order to simplify coding for young people. What you learn on Khan academy is basically fake.


This is absolutely not true. You can use khan academy knowledge if you create a canvas and activate it with javascript. @bramley


A.) Why did you only comment this on my response? Literally everyone else gave the same information except for mwilki.
B.) If you have a correct answer, how about you try to actually help ikerf with a full response, instead of criticizing me?


I helped him, I said that khan academy wasn't fake. @bramley


@Ihatenoeffort You replied snarkily to me saying that it wasn't fake, but then didn't teach him/her/they how to make it work.


Khan Academy uses ProcessingJS which has those function builtin. Normal javascript does not have these functions, however there are libraries like p5.js that offer features similar to Khan Academy's Processing JS


khan academy is probably using a library, or something that extends the functionality of javascript to be able to do these things. you could research what library they use then use that


Here is an example of ellipse and rect, but you need an HTML repl to do it.