A couple of weeks ago a friend asked me if I’d be interested doing a little contract work for the company he works for. The project was to come up with an on line quiz, mimicking that of FreeRice.com. Reasonably simple I thought, so I figured it might be good for a laugh and few pennies. The caveat being, if possible, for it to be entirely browser-side, as his company’s software did not support server-side code. Now that sounded interesting.
Being the impulsive code-monkey that I am, instead of waiting for the finalization of my contract to come through, I simply went ahead and coded the whole thing. Naturally, they decided to give this to someone internal and not hire me, so their loss is your gain. I didn’t have anything to do with this software after I’d written it, so I figured I would publish it here on my blog for the whole world to use.
The software itself is incredibly simple. Actually, I hesitate to call it software at all. It’s just one Javascript class file, some specifically name HTML elements and a single Javascript call to start the whole thing up. I like the Prototype framework, so I decided to use that to power JProQuiz, hence the “Pro” part. I also used the Scriptaculous builder so I wouldn’t have too much messy HTML in the class file. The entire class file (quiz.js) is less than 300 lines long and the majority of those are comments. (Can you tell I’m a little proud of it?)
The basic idea is a single class that acts as an engine and using a JSON configuration file, which contains all the quiz questions, options, and correct answers, drives the entire quiz experience for the user. Now, you’re probably wondering: “How do you keep the JSON config file obfuscated so that people can’t just look at the answers?” Err… well… you can’t. This quiz is entirely browser-side, so the data has to be available to the front end. The JSON file is sort of buried in the class file, so it’s definitely not immediately obvious where the questions are coming from. It would take someone who knew their way around Javascript to figure out what was going on. And if someone really wants to dig through your code and find your JSON file and read all the answers so they can get a 100% on your little web quiz, well, boogaloo for them. So, don’t use JProQuiz to power the new on line SATs, just use it for fun little quizzes.
You can download JProQuiz here.
And you can see a live example here.
If you use JProQuiz please let me know by commenting below. Or if you have any questions, suggestions, or bugs . . . bring ‘em on!
