I need help triggering an event!

I need help programming text to appear reading “YOU WIN!!!” after my health bar reaches “0”. Does anybody have any ideas for what codes to use? Here’s an image of the code I’m currently using:

First, it would be better if you post the code using three backticks (```) to format the code instead of posting an image. Also a link to your project would be helpful so we can see the HTML too.

Second, I suggest to post on processing discourse if it’s p5.js specific issue. If you crosspost, don’t forget to add a link to each other so others won’t come up with the same solution that someone else posted on another forum.

I think a quick way to solve your problem is to change the style of the DOM. This is the official document

for example you can do this to hide a DOM:

const element = document.getElementById("elt");
element.style.visibility = "hidden";

Okay. Here you go.

‘’'let img;
let loadImage;
let bulldog;

let htmlCanvas = document.getElementById(“canvas”);
let myCanvas;

let punch = document.getElementById(“fight”);
let health;
let subtraction;


function setup(){
width = 500;
height = 500;
myCanvas = createCanvas(width, height);
health = 450;
subtraction = 0.8;

function draw(){
rect(width0.05, height0.8, health, height*0.1);

punch.addEventListener(“click”, damage);

function damage(){
if (health > 0) {
console.log((health -= 45));
} else {
damage = null;

setTimeout(victory, health = 0);‘’’

that’s ', not `

1 Like

I don’t understand…

oh are you browsing on a device where ’ and ` are indistinguishable? they’re meant to be different characters. you need to use one of them to post code blocks

code blocks

but you had used the other, and it’s not showing up as a code block