I have this array that corresponds to a list of opening and closing times. I've been able to manipulate it to display what I am needing. The array corresponds to open and close times throughout the week. I am able to break up the array and list the times, but I repeat myself often, and I am wondering if there is a better, DRYer, cleaner way of doing this.
var array = ["Today at 8:00 AM", "Today at 4:00 PM",
"Tomorrow at 8:00 AM", "Tomorrow at 4:00 PM", "Thursday at 8:00 AM",
"Thursday at 4:00 PM", "Friday at 8:00 AM", "Friday at 4:00 PM",
"Saturday at 10:00 AM", "Saturday at 8:00 PM", "Sunday at 8:00 AM",
"Sunday at 4:00 PM", "Monday at 8:00 AM", "Monday at 4:00 PM"]
day1 = "Open " + array[0] + " Closed " + array[1]
day2 = "Open " + array[2] + " Closed " + array[3]
day3 = "Open " + array[4] + " Closed " + array[5]
day4 = "Open " + array[6] + " Closed " + array[7]
day5 = "Open " + array[8] + " Closed " + array[9]
day6 = "Open " + array[10] + " Closed " + array[11]
day7 = "Open " + array[12] + " Closed " + array[13]
I will admit that loops has always been my achilles heal when it comes to development. Would a loop be a solution to condensing this code a little bit? If so, how, and what kind of loop would be used?
I would like to list them out by days, similar to what I have in my very long repetitive code.
day1,day2etcday[n]dayXshould bedays = []