I need to write a code with javascript which increase the given number and sum it with a random range numbers and finally displays it. This has to be saved, because the next day, this should increment current result, using the same "sum with random range of numbers".
for instance:
Given number: 135
Random range: 5 to 20
So:
Current day=135+random range, then keep it for next 24 hours.
Next day=Current day+random range, then keep it for next 24 hours....
but I don't know how to do it, would you please help me? I really appreciate it.
An function to get a number like this is:
So if you want to use local storage(cookies) you add to function:
For further information: W3Schools JS Cookies
But if you want to store on an database in a wab server, you have to use ajax:
W3Schools Ajax Tutorial
But it don't makes sense to use
JavaScript
to do this if you'll use a server-side application (e.g.PHP
,JSP
,ASP
etc...) indeed. It will make more sense to do everything on server-side, in my oppinion.Also, you could use your own simple pseudo-random generator, which would calculate current day value depending on the initial numbers (maybe stored in cookies) and a current date. It could save space, because cookies are very strict in size.
If your aim is a client-side application and you don't have to support old browser I would suggest to use local-storage. With local-storage you can save your value. The next day you open the browser with the JavaScript-App and it will update your number. Instead starting the app manually you can use e.g. the timeout function.