I want to display 4 different videos depending on time of day (right know I only have two), I tried this way but somehow its not working, can someone tell why or help me in another effective way?
setInterval(function() {
var Today = new Date();
var H = Today.getHours();
if (H >= 5 && H < 12) {
console.log("morning");
document.getElementById("vid1").style.display = "block";
document.getElementById("vid2").style.display = "none";
} else if (H >= 12 && H < 21) {
console.log("evening");
document.getElementById("vid2").style.display = "block";
document.getElementById("vid1").style.display = "none";
} else {
console.log("night");
}
}, 3000);
<div>
<video id="vid1" muted autoplay>
<source src="video/goodmorning.mp4" type="video/mp4">
</video>
</div>
<div>
<video id="vid2" controls>
<source src="video/teste.mp4" type="video/mp4">
</video>
</div>