I am currently getting weird behavior from the following while loop in javascript.
var i = 0;
var endDate = new Date();
var startDate = new Date();
startDate.setDate(startDate.getDate() - 6);
while (start <= end){
alert (start.getDate());
start.setDate(start.getDate() + i);
i++;
}
The output I would expect (assuming today is Sept. 26) would be :
20 21 22 23 24 25 26
However I get the following output
20 20 21 23 26
I don't think I am handling the scope of the startDate variable correctly but I am not sure how to fix this.
Any help is greatly appreciated
ito the date, which is incrementing. As such, the date that is set increases from the previous sets and the currenti. Either create a date that remains unmodified, and addito that, or just add1instead ofi. jsfiddle.net/gnmvao4nstartandend?startandendare really just typos forstartDateandendDate