I'm new to JavaScript and looking for a way to create a schedule on my website. The schedule changes every half hour with different speakers, and I want to display the speaker's name based on the time slot.
Currently, I have a working solution but it involves hard-coding 48 if statements for each top and bottom of the hour - not the most efficient approach. Here is the code:
<html>
<body>
<h1>Test JavaScript</h1;
<p id="demo"></p>
<script>
setInterval(getSchedule, 1000);
function getSchedule(){
var today = new Date()
var curHr = today.getHours()
var curMin = today.getMinutes()
if (curHr == 1 && curMin < 30) {
document.getElementById("demo").innerHTML = "John";
}
else if (curHr == 1 && curMi...
I'd like to find a way to simplify this code. Possibly using an array containing all speaker names, but I'm unsure how to iterate through it at specific times. Any suggestions would be appreciated. Thanks!