Try something like this:
let animationId
function annimation() {
    ctx.clearRect(0, 0, canvas.width, canvas.height)
    tableStyle();
    animationId = requestAnimationFrame(annimation);
    ball.update();
    racketLeft.draw();
    racketRight.draw();
    if (score === 21) cancelAnimationFrame(animationId)
}
annimation();This'll stop your animation whenever score is equal to 21, just make sure you have score declared somewhere.
Want to participate?
Create a free Chris Courses account to begin