Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p id="schedule"></p>
- <script>
- function displaySchedule(scheduleArray) {
- var counter=1;
- var currentTime = new Date(); // Get the current time
- var html = '<ol style="list-style-type:none; padding: 0; margin: 0;">'; // Start ordered list markup with no bullet points and no padding/margin
- // Iterate over the schedule array
- for (var i = 0; i < scheduleArray.length; i++) {
- var scheduleTime = new Date();
- var [hours, minutes] = scheduleArray[i].split(":");
- scheduleTime.setHours(parseInt(hours, 10));
- scheduleTime.setMinutes(parseInt(minutes, 10));
- html +=(" ,<b>R"+(counter++)+":</b> ");
- // Check if the schedule time is before the current time
- if (scheduleTime < currentTime) {
- html += '<li style="display:inline;"><del>' + scheduleArray[i] + '</del></li>'; // Strikethrough for times before current time
- } else {
- html += '<li style="display:inline;">' + scheduleArray[i] + '</li>'; // Regular formatting for times after or equal to current time
- }
- // Add comma and space if it's not the last entry
- if (i < scheduleArray.length - 1) {
- html += ', ';
- }
- }
- html += '</ol>'; // End ordered list markup
- // Display the schedule in an element with id "schedule" (change the id as per your HTML)
- document.getElementById("schedule").innerHTML = html;
- }
- // Example usage:
- var scheduleArray = ["10:00", "10:45", "11:30", "12:15", "13:00", "13:45", "15:00","9:35"];
- displaySchedule(scheduleArray);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement