Slider and Math operations question

ChristophChristoph 2 hours south of Brisbane, AustraliaCommunity Member Qubie ✭

Slider and Math operations question

I am using a slider for whole values from 0 - 3 but don't know how to make sure that the choice of '0' (the starting point) is an actual choice and not just the user skipping the question. I 'solved' it by making the slider go from -1 to 3 and forcing a response. Not ideal.

I then want to use Math Operations (or javascript if needed) to calculate simple sums from the answers. However, regardless of what I try, I am unable to extract the numbers 0 - 3 from the user's answers.

This doesn't work:

D = $e{ (q://QID13/SelectedAnswerRecode/1 + q://QID13/SelectedAnswerRecode/2 + q://QID13/SelectedAnswerRecode/4 + q://QID16/SelectedAnswerRecode/1 + q://QID16/SelectedAnswerRecode/2 + q://QID16/SelectedAnswerRecode/3 + q://QID16/SelectedAnswerRecode/4 + q://QID15/SelectedAnswerRecode/1 + q://QID15/SelectedAnswerRecode/2 + q://QID15/SelectedAnswerRecode/4 + q://QID15/SelectedAnswerRecode/5 + q://QID12/SelectedAnswerRecode/3 + q://QID12/SelectedAnswerRecode/4 + q://QID12/SelectedAnswerRecode/5) * 2 }

This yields the numbers as strings and creates an output of "1 + 3 + 0 + 1..."

${q://QID13/ChoiceNumericEntryValue/1} + ${q://QID13/ChoiceNumericEntryValue/3} + ${q://QID13/ChoiceNumericEntryValue/5} + ${q://QID16/ChoiceNumericEntryValue/1} + ${q://QID16/ChoiceNumericEntryValue/3} + ${q://QID16/ChoiceNumericEntryValue/5} + ${q://QID15/ChoiceNumericEntryValue/1} + ${q://QID15/ChoiceNumericEntryValue/2} + ${q://QID15/ChoiceNumericEntryValue/3} + ${q://QID15/ChoiceNumericEntryValue/4} + ${q://QID12/ChoiceNumericEntryValue/1} + ${q://QID12/ChoiceNumericEntryValue/2} + ${q://QID12/ChoiceNumericEntryValue/3} + ${q://QID12/ChoiceNumericEntryValue/6}

It comes back with invalid calculation and when I use javascript, it comes back as NaN (not a number).

I suspect it has to do with my choice of a starting point of -1 but I don't know.

Best Answer

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭
    Accepted Answer

    For a math operation, you need to add a space after ( and before ). You also need to pipe the correct values, which I believe is ChoiceNumericEntryValue instead of SelectedAnswerRecode.

    $e{ ( (q://QID13/ChoiceNumericEntryValue/1 + ... + q://QID12/ChoiceNumericEntryValue/5 ) * 2 }

    For JS, you need to convert the strings to numbers:

    parseInt("${q://QID13/ChoiceNumericEntryValue/1}") + etc.


  • ChristophChristoph 2 hours south of Brisbane, AustraliaCommunity Member Qubie ✭

    Thank you, Tom. With the Math operations it was the closing bracket ) that did not have a space before it ... The javascript now works.

Sign In to Comment