# Instantiation not working in P5JS

**URL:** <https://discourse.processing.org/t/instantiation-not-working-in-p5js/25024>\
**Category:** Coding Questions\
**Created:** [October 29, 2020, 8:12pm UTC](https://discourse.processing.org/t/instantiation-not-working-in-p5js/25024 "2020-10-29T20:12:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nateb](https://avatars.discourse-cdn.com/v4/letter/n/b5ac83/32.png) [@nateb](https://discourse.processing.org/u/nateb)\
**Post date:** [October 29, 2020, 8:12pm UTC](https://discourse.processing.org/t/instantiation-not-working-in-p5js/25024/1 "2020-10-29T20:12:33Z")

</div>

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, radius_2, radius_2);  
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, radius_2, radius_2);  
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)

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 31, 2020, 8:02pm UTC](https://discourse.processing.org/t/instantiation-not-working-in-p5js/25024/2 "2020-10-31T20:02:33Z")

</div>

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 😉

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 :

> **[examples | p5.js](https://p5js.org/examples/instance-mode-instantiation.html)**
