lundi 5 mars 2018

How to return different variations of a string according to condition in Javascript?

I'd like to return different strings according to the conditions. I have a form of 3 questions and every question has 4 options to select from (radio) and every option has a value.. It looks like this:

Question                 Possible Answers          Value
-----------------------------------------------------------
                              1-25                   0
                              26-40                  5
question 1                    41-60                  8
                              60+                    10
-----------------------------------------------------------
                              1-25                   0
                              26-40                  5
question 2                    41-60                  10
                              60+                    10
-----------------------------------------------------------
                              1-25                   0
                              26-40                  5
question 3                    41-60                  10
                              60+                    15
-----------------------------------------------------------

I have the values for every question and now I want to return a custom string IF the sum of the values is greater than 25. In the string I want to display if a question's value is greater or equal to 10.

For example: the user chose option 2 for question 1 (value = 5), option 3 for question 2 (value = 10), and option 4 for question 3 (value = 15)

my string would be: The highest values are in question 2 and question 3.

I was hoping to do this without a huge switch statement or if statements. Please help. I hope my question makes sense. Thanks!

Aucun commentaire:

Enregistrer un commentaire