how to make an object stop at the end of your canvas p5js

JavaScript
y = constrain(y, 0, 570);

Source

Also in JavaScript: