Skip to content
Sign upLog in
← Back to Community

how do i draw a circle or a square in java script?

Profile icon
ikerf164

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?

Voters
Profile icon
AshiGupta
Profile icon
trinhphuquoc
Profile icon
thecarsont
Profile icon
Ronickson
Profile icon
freddyY2
Profile icon
ikerf164
Comments
hotnewtop
Profile icon
theangryepicbanana

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

Profile icon
eco27

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

Profile icon
bramley

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.

Profile icon
[deleted]

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

@bramley

Profile icon
bramley

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

Profile icon
[deleted]

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

@bramley

Profile icon
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.

Profile icon
mwilki7

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