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?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

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? 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT