Feeling Festive

Hi, been a few days! Working on little story sketches and relaxing for the most part (and talking with a musician whose music I’ve adored for a while now…more on that in time >w>), but now, I bring you festivities. And by that, I mean I’ll be playing with some JavaScript stuff. (And I guess listening to that one Starflyer Christmas song as I write this, but that was an accident.) But for you, it’ll be festive. Promise.

So one upgrade to somnolescent.net’s banner script I’ve been wanting to make since I wrote it is date checking. As far as the banners go, one of my inspirations has been the Video Game Critic site I’ve hovered since I was a little kid. Dave’s had these rotating banners up top for a long time, and they’re great. They’re eye-catching, collages of titles from all throughout gaming history–they just get you in the mood to play weird games. I’d recommend perusing the entire lot via the commentary page between Dave and his site designer, it’s neat just how varied they are.

The spring banner on the Video Game Critic site
I dunno, is it just me? I’m just happy to see Dig Dug and Rayman in the same image.

One of the subtle touches with these banners is that some of them are totally seasonal. One of my favorites, the one seen here, is obviously a spring banner. I knew I always wanted seasonal banners to run on somnolescent.net too, but given that we didn’t have enough banners to really test that or warrant that, I deferred it for another day.

That day happened to be today, I guess. Fast forward to this morning, and Caby came up with a new banner, one you’ll see around Halloween. (I can’t give away the festivities early!) While I figured it wouldn’t be too difficult, I was a little confused as to how JavaScript actually pulled the current system date as opposed to using a specified date (hint: it’s just today = new Date(), I’m a spastic), or if as always, I’d be able to pull it off in Netscape JavaScript.

Thankfully, this happened in about 15 minutes and there’s a nice trick involved that makes it much cleaner. It’s not impressive or anything, but I’m pleased with how clean it is.

// Year-round banners
bannerChoices = new Array("somnol", "dinos", "cops")

// Set up the dates to compare to
today = new Date()
monthCheck = today.getMonth()

switch (monthCheck) {
	case 1 :
	case 2 :
	case 3 :
	case 4 :
	case 5 :
	case 6 :
	case 7 :
	case 8 :
	case 9 :
	case 11 :
	case 10 :
	case 12 :

// Now that we've hit a season, push more banners to the selection
function festiveTime(season) {
	switch (season) {
		// case "winter" :
			// bannerChoices.push("");
			// break;
		case "spring" :
		case "summer" :
			bannerChoices.push("garden", "daf");
		case "halloween" :
		// case "christmas" :
			// bannerChoices.push("");
			// break;

The neat thing about this is the switch statement. See, switch isn’t so much a list of choices as it is a little branching roadmap; without the break statement in each case, once switch finds a case that suits it, it’ll execute all the cases afterwards as well. Normally, you don’t want this, but as I was reading through Mozilla’s Web Docs on it, I found that this can be used to your advantage if you want several cases to end in the same result. Naturally, given that a season lasts a little longer than a month, I used this to group several outcomes and make it a bit cleaner.

If I want to have a banner run during two separate seasons (like general winter ones during christmas), it’s easy to just push them to the top of the array in two separate cases. Right now, we don’t have any winter banners, so I’ve just commented them out.

Just figured I’d share that because I haven’t posted anything to the blog in a few days. Back to writing.

One Response to “Feeling Festive”

  1. mariteaux Says:

    Later update! Apparently GetMonth() counts January as the 0 month, despite GetDate() counting the first of the month as 1. This meant I had to fiddle with the cases. This is a user-friendly language and I’m convinced the future of applications is on the web.