Incrementing cookie value

So today I tried to set up a cookie on a new page - I wanted to set it up so that it would show a modal 5 times (to be sure a new user digested the additional / important information I had put on the modal). I have a modal now that comes up once (thanks to Teodor). But this one I wanted to come up 5 times. I set everything up so that the cookie would be incriminated by 1 each time the user clicks the close button on the modal.

Much to my surprise when I used +1 operator the cookie value (which I had defaulted to zero) went to 1 on the first click, then 11 on the second click and 111 on the third click. I had set the cookie variable up as a number so this did not makes much sense to me.

Next I looked for a ++ operation I could add - I could not see one (see photo below). Then I tried just using <= 11111. Another big surprise ā€“ now the cooke was showing up as FALSE vice how it behaved above.

Can someone please tell me how to increment a cookie value so I can display it the number of times I would like?

2018-11-29_08-20-24

Well you need to use the ā€˜to numberā€™ formatter first on the current cookie value, as it is a string. Thatā€™s how strings work with the + operator.

1 Like

So like this? I did make the cookie variable a number but I guess that does not matter?

cookies1.data.betaseen5.toNumber() + 1

I did not think I needed to do this because when I pull in cookies into my form page calculator they are treated as numbers not text.

2018-11-29_08-48-12

Norm, just add the toNumber formatter and that will solve your issue.

1 Like

Iā€™m sorry to be so dumb but I cannot figure out where to add the ā€œtoNumberā€ formatter - I really do try to do this stuff w/o help for hours and hours - been up since ~3 AM working on this. I donā€™t know what else to do but ask for help after trying and trying. Again, Iā€™m sorry to ask and I do really appreciate all the help you have given me.

this did not work

cookies1.data.betaseen5 + (1.toNumber())

and this did not work

cookies1.data.betaseen5.toNumber() + 1

toNumber must be added to the cookie value, not to the ā€œ1ā€ you are adding. i.e. the second example you provided.
What is not working exactly?

1 Like

I re-did it using

cookies1.data.betaseen5.toNumber() + 1

and it is working now - when I did it the first time I must have forgotten to clear my old cookie value and I thought it was going up from 1-11-111 etcā€¦ But it was not and is working now as expected!

Thank you for all your help and support - Wappler is so powerful that Iā€™m having a hard time learning all of its features but everyday I learn a little more thanks to youā€¦

1 Like