I have the following js script. It uses alert to count the days of the week day 0 Monday ... day 6 Saturday. i starts with 0 since this is js.
<script>
var days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat'];
var message = "";
for (i in days){ message += 'Day ' + i +'is ' +days[i] +'\n';}
alert(message);
</script>
I'm trying to edit i so that it begins counting from 1.
In my for ...in loop, when I increment i (i++) I get day 6 is undefined (for Saturday). When I go decrement i (i--) I get day 0 is undefined.
My questions are
1) What is the logic behind the undefined results? i is simply the counting mechanism. days is the array
//incremented i
for (i in days){ message += 'Day ' + I++ +'is ' +days[i] +'\n';}
//decremented I
for (i in days){ message += 'Day ' + I-- +'is ' +days[i] +'\n';}
2) How should I write this script to have it read day 1 is Sun...day 7 is Sat (if it can be done).