[issue] Hi can't find the problem in my code . I am new thanks

I was following The coding train video 7.4. link::

> https://www.youtube.com/watch?v=fBqaA7zRO58&list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA&index=29&ab_channel=TheCodingTrain

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);
  }
}
1 Like