Unit 3-- Lesson 18

Link

Link is to an example of what we are trying.

A student is trying to count how many times an item rotates.

We can only get it to count the rotation 1 time.

Hi @skschiltz,

Hmmm…so it sounds like you are trying to count how many time it completes 1 rotation? The only way I can think of right now is to use a tool that isn’t in the math blocks at this time but you can type it in by going to text mode and using the percent symbol. It is the modulus. The modulus captures the remainder if two numbers are divided together. It is commonly used to test for even or odd numbers because the remainder for even numbers divided by 2 is always 0.

On the exercise you linked to, when I added **soup.rotation** to the watcher, it just continually adds so that a full circle would show 360 and two rotations shows 720. So, if I add the following code, it counts how many rotations since **soup.rotation** divided by 360 should be evenly divisible and therefore always have a remainder of 0 (FYI I set var x = 0 above the draw loop):

If there is another way to do this, hopefully someone will share it:)

~Michelle

Greetings @skschiltz,

While I agree @melynn’s approach is useful if you want to execute additional code once it counts a rotation you can also calculate it this way

```
console.log(Math.abs(Math.trunc(spr.rotation/360)))
```

and it will techincally give the same result except with less work being made for counting it with storing such a result being optional

additionally if your only dealing with positive numbers you can ditch the abs() protocol or if you want to count it as counter rotations best of luck though!

If there are 360 points in a rotation, you could add a console log statement and divide the rotation points by 360

Would that help?