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?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education