How to add tolerance to an if statement in Javascript

I learn JavaScript with the p5js library and I decided to create a very basic game.

I just want the game to end when the condition of an if statement is met.
Such as

if (x == y) {
>>> endcode here <<<

However, I have to add a tolerance of 50 to each value.

so the code would be something like

if (x == y (give or take 50)) {
>>> endcode here <<<

I do not know how to add tolerance to the statement, so I came here to help you.
Thank you 🙂