Answer the question
In order to leave comments, you need to log in
How to correctly write a program for testing?
So I came up with a task for the weekend) In the morning I stumbled upon this picture and thought "why not write a program for such a task?"
At the moment, I think that it would be better to describe this whole scheme in json format, you will get a tree structure. The user clicks on options, some function parses a certain piece of json and returns the next options. And all these people are interested in the opinion of javascript programmers. What technical solution would you choose for such a task?
Answer the question
In order to leave comments, you need to log in
An ordinary tree is a question, a list of possible answers with transitions to the next nodes or leaves. It can be presented in any way, through JSON, XML, a pre-prepared array, etc.
You can place all the blocks on the page at once in nested divs and open / close the ones you need as you select answers.
You can draw a diagram as an SVG and handle clicks on select elements by highlighting the path traveled.
Check out the State Machine pattern. There are ready-made implementations, for example https://github.com/jakesgordon/javascript-state-machine
Wrote like a mobile application for surveys. The polls themselves with answer options and all branches were stored in json (an array of objects). The format is something like this:
[
{
id: 1,
title: 'Итак, тебе нужен шрифт',
desc: 'Начни с того для чего он тебе нужен',
answers: [
{
title: 'Логотип',
nextQuestion: 2
},
{
title: 'Газета',
nextQuestion: 3
},
{
title: 'Приглашение',
nextQuestion: 4
},
{
title: 'Инфографика',
nextQuestion: 5
}
]
},
{
id: 2,
answers: [
{
title: 'Без засечек, наверно?',
nextQuestion: 6
},
{
title: 'Или возможно с засечками?',
nextQuestion: 7
}
]
},
{
id: 3,
answers: [
title: 'Какого типа газета должна быть?',
{
title: 'Текстовая',
nextQuestion: 8
},
{
title: 'Визуальная',
nextQuestion: 9
},
{
title: 'Смесь',
nextQuestion: 10
}
]
},
........................
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question