---
title: "Comment by Gunaraj Khatri on \"02 Game Loops\" | Hashnode"
description: "Challenge of bounce to-fro: modify in update() method if ( this .x= = = 0 ){ this .count- - ; } if ( this .x= = = canvas.width){ this .count+ + ; } if ( this .c"
url: "https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a/comment/624fce367f832067321eb1c9"
---

[Discussion](https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a)

Comment [02 Game Loops](https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a)

[Gunaraj Khatri](https://hashnode.com/@gunaraaj)

[Apr 8, 2022](https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a/comment/624fce367f832067321eb1c9)

Challenge of bounce to-fro: modify in update() method

```
 if(this.x===0){
      this.count--;
    }
    if(this.x===canvas.width){
      this.count++;
    }
    if(this.count===0){
    this.x += this.speedX;
    this.y += this.speedY;
    }
    else{
       this.x -= this.speedX;
    this.y -= this.speedY;
    }
```

_initially count is supposed to be 1_

[Sudarshan Rai](https://hashnode.com/@sudarshanrai)

[Apr 8, 2022](https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a/comment/624fce367f832067321eb1c9#reply-624fd4fbbd2d386758329dfb)

[Gunaraj Khatri](https://hashnode.com/@gunaraaj)Nice one, Also You can add rect width to rect x position to get rect right side of the for bounce.

```
if(this.x + this.width === canvas.width)
```

[Gunaraj Khatri](https://hashnode.com/@gunaraaj)

[Apr 8, 2022](https://hashnode.com/posts/02-game-loops/624efb667f832067321ea09a/comment/624fce367f832067321eb1c9#reply-624fea2c7f832067321eb4a9)

[Sudarshan Rai](https://hashnode.com/@sudarshanrai) oh, yeah!!
