equation question - syntax issue

More
5 months 2 weeks ago #173411 by marektondryk


I have 3 questions (q1, q2, q3) radio list each one with answers 'yes' (A1) and 'no' (A2).
I want answer returned from equation question for condition:
{if answer for q1=A2 and answer for q2=A2 and answer for q3=A2 than "red" or
if answer for q1=A1 and answer for q2=A2 and answer for q3=A2 than "green" or
if answer for q1=A1 and answer for q2=A1 and answer for q3=A2 than "blue" or
if answer for q1=A1 and answer for q2=A1 and answer for q3=A1 than "yellow"}

How should this equation question look like?
Attachments:

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago - 5 months 2 weeks ago #173415 by DenisChenu
I do :
{join(
if(q1=="A2" and q2=="A2" and q3=="A2",'red',''),
if(q1=="A1" and q2=="A2" and q3=="A2",'green',''),
if(q1=="A1" and q2=="A1" and q3=="A2",'blue',''),
if(q1=="A1" and q2=="A1" and q3=="A1",'yellow',''),
'')}
Because it's more simple to understand and fix then imbricated if : manual.limesurvey.org/Expression_Manager...Conditional_Logic.29

(corrected)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last edit: 5 months 2 weeks ago by DenisChenu. Reason: Use == not = silly boy
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173418 by jelo

However, we recommend using the join() function for concatenation, as that makes your intent more clear, and avoids unexpected results if you were expecting strings but got numbers instead (or vice versa).

manual.limesurvey.org/Expression_Manager#Operators

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173421 by tpartner
Why the join function? Since they are mutually exclusive, why not simply use four IF() statements (not nested)?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago - 5 months 2 weeks ago #173422 by DenisChenu

tpartner wrote: Why the join function? Since they are mutually exclusive, why not simply use four IF() statements (not nested)?

Maybe in future Equation question type save line feed ;).

But currently : you're right, can be done with
{if(q1=="A2" and q2=="A2" and q3=="A2",'red','')}
{if(q1=="A1" and q2=="A2" and q3=="A2",'green','')}
{if(q1=="A1" and q2=="A1" and q3=="A2",'blue','')}
{if(q1=="A1" and q2=="A1" and q3=="A1",'yellow','')}

(Edited/corrected)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last edit: 5 months 2 weeks ago by DenisChenu. Reason: Use == not = silly boy !
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173446 by marektondryk
Thanks guys :)
I put code:
{if(q1="A2" and q2="A2" and q3="A2",'red','')}
{if(q1="A1" and q2="A2" and q3="A2",'green','')}
{if(q1="A1" and q2="A1" and q3="A2",'blue','')}
{if(q1="A1" and q2="A1" and q3="A1",'yellow','')}

into new equation question and I don't get yellow,blue, etc. answer...
What should I do???? :(

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173448 by holch
Send a LSS file with what you have done.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173455 by marektondryk

File Attachment:

File Name: test.lss
File Size:16 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago - 5 months 2 weeks ago #173457 by vkuzmin
Use dual equality == to compare values
UPD: And use quotes instead of apostrophes.
Last edit: 5 months 2 weeks ago by vkuzmin.
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173471 by tpartner

Use dual equality == to compare values

Duh...that's a rookie mistake, not catching that :)

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: marektondryk

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173479 by marektondryk
Thanks!!!!! :) Works GREAT!!!

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173482 by DenisChenu

tpartner wrote:

Use dual equality == to compare values

Duh...that's a rookie mistake, not catching that :)

Arg … my mistake … :S

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173571 by marektondryk
Is it possibe to set condiotion e.g.
{if(q1=="A2" and q2=="A1" and q3=="A1",'Yor answers aren't logical','')}
which doesn't allow to click button NEXT?

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173574 by tpartner
Depending on the question type, you can use the Question validation equation and Tip for whole question validation equation - manual.limesurvey.org/Question_type_-_Li...28em_validation_q.29

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #173575 by marektondryk
May I use this for 3 radio list questions condition or just for one?

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!