+ 4

Why doesn't this code work , am trying to make 10 ball with this code by using push and loop

onload = () => { init() ball() } let w , h , cr , c w = innerWidth h = innerHeight cr = ["red","lightblue","green","yellow","orange"] cr = Math.floor(Math.random()*cr.length) const init = () => { c = document.createElement("canvas") c = c.getContext("2d") c.width = w c.height = h document.body.appendChild(c) } const ball = () => { x = Math.floor(Math.random()*w) y = Math.floor(Math.random()*h) r = 20 draw = () => { c.beginPath() c.fillStyle = cr c.arc(x,y,r,0,2*Math.PI) c.fill() c.closePath() } }

11th Sep 2019, 5:38 PM
SCP 251
SCP 251 - avatar
5 Respostas
+ 3
It will work because this is a code playground https://code.sololearn.com/W3Eoch1hwAOq/?ref=app
12th Sep 2019, 7:05 AM
Calviղ
Calviղ - avatar
+ 4
you mistakenly used the same variable c for both canvas and context use separate variables for example cnv for canvas ctx for context https://www.sololearn.com/post/117756/?ref=app https://code.sololearn.com/WKKkpq0efxai/?ref=app
12th Sep 2019, 4:51 AM
Gordon
Gordon - avatar
+ 2
Cbr✔[ Exams ] lol very true
11th Sep 2019, 6:18 PM
Dace [Super Inactive| Challenge=Maybe]
Dace [Super Inactive| Challenge=Maybe] - avatar
+ 2
Thank you so much
12th Sep 2019, 7:35 AM
SCP 251
SCP 251 - avatar
0
I don't understand
11th Sep 2019, 8:07 PM
SCP 251
SCP 251 - avatar