Bouncing Balls Project Doesn't Run As Expected

Good morning,

I am trying to complete the Bouncing Balls project and have run into a wall.

https://www.codecademy.com/projects/practice/p5js-bouncing-balls

Things were moving along just fine until I got to step 10 where the instructions say “After you draw the ellipses and run the code, you will see white ellipses gathered in the middle of your canvas.” I clicked save and got nothing. I looked and looked and corrected a couple small things and still nothing. I kept going and figured mine would show up eventually. No matter what I did, I got nothing.

I watched the YouTube video, did it exactly like he did and still nothing.

No matter what I do, I get nothing.

I can see that the functions are declared and set up, but are never actually called and ran, but that is no different than the video and they ran fine.

What am I missing? Any help or pointers would be great.

let ballCount = 100; let x = []; let y = []; let xSpeed = []; let ySpeed = []; let r = []; let g = []; let b = []; let size = []; function setup() { createCanvas(windowWidth, windowHeight); for (let i = 0; i < ballCount; i++) { x[i] = width / 2; y[i] = height / 2; xSpeed[i] = random(-5, 5); ySpeed[i] = randcom(-5, 5); size[i] = random(10, 50); r[i] = random(0, 256); g[i] = random(0, 256); b[i] = random(0, 256); } } function draw() { background(0, 50); for (let i = 0; i < ballCount; i++) { x[i] += xSpeed[i]; y[i] += ySpeed[i]; if (x[i] < 0 || x[i] > width) { xSpeed[i] *= -1; } if (y[i] < 0 || y[i] > height) { ySpeed[i] *= -1; } fill(r[i], g[i], b[i]); noStroke(); ellipse(x[i], y[i], size[i], size[i]); } }

Line 17 has a typo.

ySpeed[i] = randcom(-5, 5);
1 Like

Dangit. Thanks, that was it. Works like a charm now.

It seems like it’s often one little thing.