Branching
You can show a user different pages depending on how they’ve answered a question.
To do this, add some JavaScript to your routes.js file.
Branching on radio button answers
Send users to different pages based on their radio button selection:
Branching on checkbox answers
Checkboxes return a list of checked values, so there can be many more possible combinations.
You can use the JavaScript includes() function to test if the list of checked values includes the one you specify within the brackets.
To test if any of of several checkboxes have been checked, combine several of these with ||, which means ‘or’.
To test if multiple checkboxes have all been checked, combine several of these with &&, which means ‘and’.
Branching on number inputs
If you use a text input to ask the user to input a number, such as their age, you can then branch based on that number.
All text inputs will be treated as a string of text instead of a number by JavaScript, so you will have to first use Number() to convert the string to a number.
You can then use these operators to test the number:
===- equal to!==- not equal to>– more than>=– more than or equal to<– less than<=– less than or equal to