I'm working on a JS project where I create a daily scheduler and each hour should be color coded based on if it is past, present, or the future.
The schedule goes from 9am to 5pm. Currently it is applying the class for future to every block, so every row shows up as green. Instead, say if it were 11am, then the row for 11am would be highlighted red for present time, the rows for the hours before 11am would be grey or transparent and the hours in the future would be green.
I have set Ids for each of my hour blocks to parse through and compare with the current hour, but for some reason it isn't working. I already have the classes set up in my CSS for past present and future.
var blocks = document.getElementsByClassName("description");
var hourBlock = parseInt(moment().format('H'));
Array.from(blocks).forEach(description => {
let idString = description.id, rowHour;
if (idString) {
rowHour = parseInt(idString);
}
if (rowHour) {
if (hourBlock === rowHour) {
$(".description").addClass("present")
} else if (hourBlock < rowHour) {
$(".description").addClass("past")
} else {
$(".description").addClass("future");
}
}
});