multiple criteria logic with ‘greater than’ in custom scripting?

0

Hi! 

I have a multiple slider question and I want to show a follow up question for the top ranking slider.

First I’m pulling the slider values with hidden actions (question_ids 8, 9, 10, 11) and then I’m trying to show a follow up question (question_ids 4, 5, 6, or 7) depending on which value in questions 8, 9, 10, 11 is highest.

I currently have the sliders on page 1; the hidden value scraping on page 2 (question_ids 8, 9, 10, 11 — auto running and auto submitting); the script below on page 3 (auto running and auto submitting); and the questions I want to show/hide on page 4 (question_ids 4, 5, 6, 7)

 

Here’s my custom scripting:

 

sgapiHideQuestion(4, true);
sgapiHideQuestion(5, true);
sgapiHideQuestion(6, true);
sgapiHideQuestion(7, true);

%%food = sgapiGetValue(8);
%%activity = sgapiGetValue(9);
%%sleeep = sgapiGetValue(10);
%%stress = sgapiGetValue(11);

if (%%food > %%activity) && (%%food > %%sleeep) && (%%food > %%stress)
{
sgapiHideQuestion(4,false);
}

if (%%activity > %%food) && (%%activity > %%sleeep) && (%%activity > %%stress)
{
sgapiHideQuestion(5,false);
}

if (%%sleeep > %%food) && (%%sleeep > %%activity) && (%%sleeep > %%stress)
{
sgapiHideQuestion(6,false);
}

if (%%stress > %%food) && (%%stress > %%activity) && (%%stress > %%sleeep)
{
sgapiHideQuestion(7,false);
}

 

 

When I run this, none of the questions end up being hidden. :( Again, I just want one of them to show (I realize that I need to deal with the situations when two values are equally high, but I’m just trying to at least get this to work!

 

 

If I change the code to something that takes out the multiple criteria logic and ‘greater than’ operands, and if make sure that question_id 8 = 6, this script below will hide questions 5, 6, and 7 and show question 4.

 

sgapiHideQuestion(4, true);
sgapiHideQuestion(5, true);
sgapiHideQuestion(6, true);
sgapiHideQuestion(7, true);

%%food = sgapiGetValue(8);
%%activity = sgapiGetValue(9);
%%sleeep = sgapiGetValue(10);
%%stress = sgapiGetValue(11);

if (%%food = 6)

sgapiHideQuestion(4,false);

}

 

 

Does anyone have hint on how to do the multiple criteria logic with greater than operands above?

 

Thank you!

geogiz answered
    0

    i’m not a php expert, but here are some suggestions:

    1. make sure you’re running the test with ‘fire actions’ toggeled on.
    (altough, if you can hard code it to get results, then it’s probably fine).
    2. make sure youre getting integer values form sgapigetvalue
    (which it seems you are).
    3. you’re probably correct in assuming that the multiple criteria bits are whats causing the problem. try putting the entire chain inside parthenessis:

    try:
    if ((%%food ==6)&&(%%activity==5)){
    sgapihidequestion(4,false);
    }


    If this works, then you can move on to substituing it with your actual values.


    4. i’ve also noticed that you used an assingment operator (‘=’) and not equallity opertator (‘==’), it’s not directly related to your problem, but you should make notice of it.

    I hope it works.

    geogiz edited answer
      ×

      Login

      Question stats

      • Active
      • Views810 times
      • Answers1 answer
      • Followers1 follower