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
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