I am coding in p5.js and I am unable to understand what is wrong with my code. I am getting the error that is listed in the title. I am new to js and I require some help. I attempted some switching around and other methods however i am unable to get rid of my errors. I will attempt some troubleshooting myself in the meantime but if anyone has a solution to this, I assume, simple problem then lmk.
let meteorX = []; // Create array to store X positions of meteors
let meteorY = [0, 0, 0, 0, 0]; // Create array to store Y positions of meteors
let meteorDiameter = []; // Create array to store diameter of meteor
let catcherDiameter = 40; // Store diameter of the catcher
let distance = []; // Create array to store the distance between meteor and catcher
let zoom = []; // Create array to store meteor speed
let numMeteorsCaught = 0; // Store the number of meteors caught
let bgImage;
let sombrero;
let tacoImg;
// Only runs once
function setup() {
createCanvas(400, 400);
// Load images and store
bgImage = loadImage('bgImage.png');
sombrero = loadImage('Player.png');
tacoImg = loadImage('download.png');
// Populate initial X values
for(let i = 0; i < 5; i++){
meteorX[i] = random(0, width);
}
// Populate initial diameter values
for(let i = 0; i < 5; i++){
meteorDiameter[i] = random(10, 40);
}
// Populate initial speed values
for(let i = 0; i < 5; i++){
zoom[i] = random(0.5, 4);
}
}
// Runs over and over in a loop
function draw() {
imageMode(CORNER);
background(bgImage);
noStroke();
// Draws the image starting from the center
imageMode(CENTER);
// Draw meteors to the screen
for(let i = 0; i < 5; i++){
image(tacoImg[i], meteorY[i], meteorDiameter[i], meteorDiameter[i]);
}
// Cycle through meteors to make them fall at different speeds
for(let i = 0; i < 5; i++){
meteorY[i] = meteorY[i] + zoom[i];
}
// Draw the catcher to follow the mouse
image(sombrero, mouseX, mouseY, catcherDiameter, catcherDiameter);
// Cycle through meteors to determine distance between meteor and catcher
for(let i = 0; i < 5; i++){
distance[i] = dist(meteorX[i], meteorY[i], mouseX, mouseY);
print('distance = ' + distance[i]);
}
// Cycle through meteors to test if meteor and catcher have intersected
for(let i = 0; i < 5; i++){
if(distance[i] < 15){
// Redraw meteor to top of screen at a random location on x-axis
meteorY[i] = 0;
meteorX[i] = random(0, width);
// Set new meteor speed to random number between 1 and 4
meteorDiameter[i] = random(10, 40);
// Increase the score value by 1
numMeteorsCaught = numMeteorsCaught + 1;
}
}
// Cycle through meteors to test if intersected with screen bottom
for(let i = 0; i < 5; i++){
if(meteorY[i] > height){
meteorY[i] = 0;
meteorX[i] = random(0, width);
meteorDiameter[i] = random(10, 40);
}
}
// Draw the score to the screen
fill(0, 254, 202);
textAlign(LEFT);
textSize(20);
text('Meteors Caught: ' + numMeteorsCaught, 20, 380);
}```