Is there a way to get an incresing number in JavaScript? The number should increase from 1 to 6 every day. Example:
1st day: 3
2nd day: 5 (3+2)
3rd day: 6 (5+1)
4th day: 12 (6+6)
5th day: 16 (12+4)
...
I guess I need some base value because I can not save the numbers anywhere. I tried using the following code as base value:
new Date().getTime()
But this value is just too big.
Thanks for helping!
Ok, given your comments I think this should be what you are looking for:
var rand_num = Math.floor((Math.random() * 6) + 1);
var result = index_num + rand_num
This result
will be whatever index you deliver plus a random integer between one and six inclusive. Just use result as the next index for each subsequent day.
You are probably looking for:
var day1 = Math.floor((Math.random() * 6) + 1);
var day2 = day1 + Math.floor((Math.random() * 6) + 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.