I need help fixing this error within my p5js code : TypeError: undefined is not an object (evaluating 'se1.play') TypeError: undefined is not an object (evaluating 'se2.play') TypeError: undefined is not an object (evaluating 'se3.play') Here is my code: let se1, se2, se3; // declare sound variables let ellipse1, ellipse2, ellipse3; // declare ellipse variables function preload() { se1 = loadSound('SE1.mp3'); se2 = loadSound('SE2.mp3'); se3 = loadSound('SE3.mp3'); } function setup() { createCanvas(400, 400); ellipse1 = { x: 50, y: 50, size: 50 }; ellipse2 = { x: 150, y: 150, size: 50 }; ellipse3 = { x: 250, y: 250, size: 50 }; } function draw() { background(220); noStroke(); fill(255, 0, 0); ellipse(ellipse1.x, ellipse1.y, ellipse1.size); fill(0, 255, 0); ellipse(ellipse2.x, ellipse2.y, ellipse2.size); fill(0, 0, 255); ellipse(ellipse3.x, ellipse3.y, ellipse3.size); } function mouseClicked() { // check if mouse is inside ellipse 1 if (dist(mouseX, mouseY, ellipse1.x, ellipse1.y) < ellipse1.size / 2) { se1.play(); } // check if mouse is inside ellipse 2 else if (dist(mouseX, mouseY, ellipse2.x, ellipse2.y) < ellipse2.size / 2) { se2.play(); } // check if mouse is inside ellipse 3 else if (dist(mouseX, mouseY, ellipse3.x, ellipse3.y) < ellipse3.size / 2) { se3.play(); } } How can I fix this problem when I clearly set the variables at the beginning of my code?
I need help fixing this error within my p5js code :
TypeError: undefined is not an object (evaluating 'se1.play')
TypeError: undefined is not an object (evaluating 'se2.play')
TypeError: undefined is not an object (evaluating 'se3.play')
Here is my code:
let se1, se2, se3; // declare sound variables
let ellipse1, ellipse2, ellipse3; // declare ellipse variables
function preload() {
se1 = loadSound('SE1.mp3');
se2 = loadSound('SE2.mp3');
se3 = loadSound('SE3.mp3');
}
function setup() {
createCanvas(400, 400);
ellipse1 = { x: 50, y: 50, size: 50 };
ellipse2 = { x: 150, y: 150, size: 50 };
ellipse3 = { x: 250, y: 250, size: 50 };
}
function draw() {
background(220);
noStroke();
fill(255, 0, 0);
ellipse(ellipse1.x, ellipse1.y, ellipse1.size);
fill(0, 255, 0);
ellipse(ellipse2.x, ellipse2.y, ellipse2.size);
fill(0, 0, 255);
ellipse(ellipse3.x, ellipse3.y, ellipse3.size);
}
function mouseClicked() {
// check if mouse is inside ellipse 1
if (dist(mouseX, mouseY, ellipse1.x, ellipse1.y) < ellipse1.size / 2) {
se1.play();
}
// check if mouse is inside ellipse 2
else if (dist(mouseX, mouseY, ellipse2.x, ellipse2.y) < ellipse2.size / 2) {
se2.play();
}
// check if mouse is inside ellipse 3
else if (dist(mouseX, mouseY, ellipse3.x, ellipse3.y) < ellipse3.size / 2) {
se3.play();
}
}
How can I fix this problem when I clearly set the variables at the beginning of my code?
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)