Instantiation not working in P5JS

I need to instantiate this so I can combine it with other sketches but keep getting an error. PLS HELP

const radius = 100;
let x, y;
//code for icons
p.setup = function(){
p.createCanvas(windowWidth, windowHeight);
x = p.random(windowWidth);
y = p.random(windowHeight);
p.textAlign(CENTER);
setInterval(timeIt, 1000)
};

p.draw = function(){
p.background(200);
p.fill(255, 0, 255);
p.noStroke();
p.ellipse(x,y, radius2, radius2);
p.fill (50, 10, 90);
p.text(" Score: " + score, 10, 20);
p.fill (10, 0, 80);
if (timerValue >= 10) {
p.text(“0:” + timerValue, width / 2, height / 2);
}
if (timerValue < 10) {
p.text(‘0:0’ + timerValue, width / 2, height / 2);
}
if (timerValue == 0) {
p.fill(200, 200, 200);
p.noStroke();
p.ellipse(x,y, radius2, radius2);
p.fill (50, 10, 90);
p.text('game over // ’ + "your score was: " + score, width / 2, height / 2 + 15);
}
};

p.mousePressed = function(){
let d = p.dist(mouseX, mouseY, x, y);
if (d < radius){
x = p.random(windowWidth);
y = p.random(windowHeight);

score++;

}
else{
score–;
}
};
let score = 0;

p.timeIt = function() {
if (timerValue > 0) {
timerValue–;
}
};
};
let myp5 = new p5(sketch);

my error is : Called from line in “promiseReactionJob” in [native code] ([native code]:undefined:undefined)

Hi,

First of all, please make sure to format your code by using the </> button in the message editor on the forum. Also you can auto indent it by using the p5js online editor of the IDE :wink:

Also there was errors in your code timerValue–;, score–; ? It’s more timerValue--; and score--

And p is not defined if you don’t declare and instantiate it at the top of your code, anyway check this page on how to make an instance of p5js :

1 Like