Issue at hand:
In my current script, I've defined an array named "weekdays":
const weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
Let's say it's Saturday and I need to determine the number of days until Tuesday (which is 3 days). How can I navigate through the array - starting from "Sat" and looping back to the beginning until we reach "Tue"?
The code snippet I've implemented so far:
const weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const start = weekdays.indexOf("Sat");
const end = weekdays.indexOf("Tue");
let howManyDays = 0;
for (let i = start; i < end; i = (i + 1) % weekdays.length) {
howManyDays++;
}
But when testing this code in the browser console, it appears that the variable "howManyDays" remains at 0. Any assistance on why this might be happening would be appreciated.