# Assignment operator

**URL:** https://discourse.processing.org/t/assignment-operator/10249
**Category:** Beginners
**Created:** [April 14, 2019, 2:48am UTC](https://discourse.processing.org/t/assignment-operator/10249 "2019-04-14T02:48:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jdk](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jdk](https://discourse.processing.org/u/jdk)
#### Post date: [April 14, 2019, 2:48am UTC](https://discourse.processing.org/t/assignment-operator/10249/1 "2019-04-14T02:48:42Z")

</div>

I was preparing simple animation game of bouncing ball.  
There I have to insert an assignment condition for collision with a paddle to bounce.  
But it seems that p5js isn’t compatible with assignment operator.  
Its not assigning. The program stops when run on browser.

Please give me any solution to this problem.

here is that assignment statement:

```auto
(ball.yCor+rad == pad.yPaddle)

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 14, 2019, 3:27am UTC](https://discourse.processing.org/t/assignment-operator/10249/2 "2019-04-14T03:27:19Z")

</div>

> **[Assignment operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators)**
>
> An assignment operator assigns a value to its left operand based on the value of its right operand.

> **[Comparison operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality_operators)**
>
> JavaScript has both strict and type–converting comparisons. A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands to the...

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 14, 2019, 4:30am UTC](https://discourse.processing.org/t/assignment-operator/10249/3 "2019-04-14T04:30:59Z")

</div>

possibly a little example  
[https://editor.p5js.org/kll/sketches/BUJhZfVvz](https://editor.p5js.org/kll/sketches/BUJhZfVvz)  
helps too.

---

<div class="post-metadata">

### Author: ![jdk](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jdk](https://discourse.processing.org/u/jdk)
#### Post date: [April 17, 2019, 1:20am UTC](https://discourse.processing.org/t/assignment-operator/10249/4 "2019-04-17T01:20:39Z")

</div>

Thanks for reply. I do made changes but still why you didn’t used ‘==’ operator to check ball’s collision with the paddle?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 17, 2019, 1:39am UTC](https://discourse.processing.org/t/assignment-operator/10249/5 "2019-04-17T01:39:37Z")

</div>

[CrHallberg.com/CollisionDetection/Website/circle-rect.html](http://CrHallberg.com/CollisionDetection/Website/circle-rect.html)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 17, 2019, 4:48am UTC](https://discourse.processing.org/t/assignment-operator/10249/6 "2019-04-17T04:48:44Z")

</div>

> [@jdk](#):
>
> why you didn’t used ‘==’ operator

just think what would happen if you use float numbers, and

> ballyCor + rad == 12.0000001

> padyPaddle == 12

it would be too late to stop it ( using == ).  
so better check for overrange and reset it hard.

> ballyCor = padyPaddle - rad;

later you might be using variable speed in your position calculation.
