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