Ask coding questions

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

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?

Comments
hotnewtop
bramley (254)

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.

[deleted]

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

bramley (254)

@Ihatenoeffort
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?

[deleted]

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

bramley (254)

@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.

theangryepicbanana (1694)

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

MrEconomical (2290)

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

mwilki7 (1137)

Here is an example of ellipse and rect, but you need an HTML repl to do it.
https://repl.it/@mwilki7/canvas-example