1

I have a web project that requires I build a quiz and am having some difficulty working out how to efficiently code it. I'd like to create some sort of json template system so that the quizzes can be defined in a config file, my problem is that almost every question on the quiz is structured differently.

So some questions are simple yes/no answers, some have text input, some are multiple choice. Now this is not too difficult to do by defining the question attributes in json but there is also some logic involved. For example:

If question 2 is answered no and question 3 is answered no, then go back to question 2 and ask it again but only ask it twice, otherwise go to question 4.

This is where I am struggling, as I've said I'd like to create some sort of json template system so that the quizzes can be defined in a config file but I cannot think of a way to do that with logic in the quiz.

Any ideas?

  • 2
    Who will they be defined by? You? Another developer? The customer? An average user? – biziclop Nov 29 '15 at 20:58
  • I'll be defining them – user2424495 Nov 29 '15 at 21:00
  • 1
    In that case I'd probably define some kind of finite state machine to handle the transitions between questions. So you'd have two structures, a simple list of all the questions (and their type and possible answers) and a set of transition rules. – biziclop Nov 29 '15 at 21:39