JavaScript – Running code only on certain days or months

Perfect for easter eggs or logic bombs.

HTML:

<!-- SHOW ON FRIDAY ONLY -->
<div id="dayofweek5" style="display:none">
    <button class="friday" onmousedown="javascript:PlayVideo('./videos/friday.mp4')" >&nbsp;</button> 
</div>

<!-- SHOW IN DECEMBER ONLY -->
<div id="month11" style="display:none">
    <button class="airhornxmas" onmousedown="javascript:PlaySound('./sounds/airhorn_xmas.mp3')" >Air Horn Xmas!!</button> 
</div>

JavaScript:

function showhide() {
    var d = new Date();
	var datenumber = +d.getDay()
	var monthnumber = +d.getMonth()
	var daydiv = "dayofweek"+(+d.getDay())
	var monthdiv = "month"+(+d.getMonth())
	
	// SHOW FRIDAY ITEM
    if (datenumber === 5){
		var s = document.getElementById(daydiv);
		s.style.display = (s.style.display == 'block') ? 'none' : 'block';
		}

	// SHOW DECEMBER ITEM
    if (monthnumber === 11){
		var s = document.getElementById(monthdiv);
		s.style.display = (s.style.display == 'block') ? 'none' : 'block';
		}
}
showhide();

Leave a Reply

Your email address will not be published. Required fields are marked *