I'm currently working on a website utilizing HTML, JavaScript and CSS(Big woop - I know).
I'm running bootstrap to learn how to make a website a bit more responsive. I'm currently trying to learn the different date functions in JavaScript and want my website to highlight different list-elements depending on what day of the week it is.
<ul class="list-group">
<li class="list-group-item" >Mondays: 09:00 - 16:00</li>
<li class="list-group-item">Tuesdays: 09:00 - 16:00</li>
<li class="list-group-item">Wednesdays: 09:00 - 16:00</li>
<li class="list-group-item">Thursdays: 09:00 - 16:00</li>
<li class="list-group-item">Fridays: 09:00 - 12:00</li>
<li class="list-group-item">Saturdays: Closed</li>
<li class="list-group-item">Sundays: Closed</li>
</ul>
The list itself is a standard unordered list which displays opening hours and what I want to create through JavaScript is that if the website senses that today is Monday it'll highlight Monday.
I have written the following code to get the website to check date:
function daysOpen(){
let daysOfWeek = ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let dateObject = new Date()
let today = dateObject.getDay();
//console.log("Today is: " + today); // generates output to console
//console.log(daysOfWeek[today]) <- This is used for debugging
if(daysOfWeek[today] === 'Saturday' || daysOfWeek[today] ==='Sunday'){ // This piece of code lets me check date from
//system time(?) and compare against my array to see if today is open or closed
console.log("Store is closed")
}
else
{
console.log("The store is open")
}
}
This is where I get stuck. I'm not sure how to use the if-statements to highlight the list elements and I haven't been able to find a good example or guide online. The most similar question I could find was this: text depend on time of day and day of week
But I'm still having troubles understanding how to continue.
Any help is greatly appreciated.