Up Down Counter

New to Node red and just learning its functions.

I want to create a counter that counts when a message is received.

The complication is I want it to count from 1 to 3 and then decrement from 3 back to 1 and continue to do this

I want to be able to create an action for each of the 3 states.

Any help appreciated.

This will help you: https://www.youtube.com/watch?v=SuoSXVqjyfc from @TheHookUp

Pay attention to the scope part. A flow scoped variable is probably what you need.