Sadly, I can't put all of the code in this window, but here's the link to the project: https://editor.p5js.org/thing1/sketches/KIsvdFvPt
You can duplicate it to edit it and look at all of the files if you so wish. I'm sorry this is such a vague question, but I've worked so hard on this program and now it feels like it's all been for nothing. Any help is appreciated :) I really appreciate any help you can provide. Many thanks!
Firstly, as mentioned in the comments you're removing from an array whilst iterating through it. This is often needed in game development and the common practice is to iterate through the array backwards:
for (let i = comets.length - 1; i >= 0; i--) {
// do your removing
}
However, this is only part of the problem. The reason your sketch is freezing, is because you've got the following code in your Comet class:
polygon(this.x,this.y,this.health*2,this.health/5)
So you're setting the radius and npoints of the polygon to values dependent upon the health of the asteroid, you can imagine why it doesn't like it when a negative value is set!
Wrap this code in a simple if:
if (this.health > 0) {
polygon(this.x, this.y, this.health*2, this.health/5)
}