I was following The coding train video 7.4. link::
and I can’t find the problem I am facing. it says Uncaught TypeError: Cannot read property ‘move’ of undefined (sketch: line 24).
Here is my code
let bubble = [];
function setup() {
createCanvas(600, 400);
}
function mousePressed() {
let r = random(10, 50);
let b = new Bubble(mouseX, mouseY, r);
bubble[0] = b;
}
function draw() {
background(140, 140, 20);
for (i = 0; i <= bubble.length; i++) {
bubble[i].move();
bubble[i].show();
}
}
class Bubble {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
}
move() {
this.x = this.x + random(-5, 5);
this.y = this.y + random(-5, 5);
}
show() {
stroke(255);
strokeWeight(1);
fill(15, 94, 156);
ellipse(this.x, this.y, this.r);
}
}