Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to use divide "/" function and between (50 to 100) in an if/else statement

alik98709228
Level 3
Level 3

Hello,

 

In my list, there are two columns, Men and Women. Men value is '10', Women value is '5'.

I wan to convert following formula to use in an if else statement:

 

if (Men - Women) / Men == '50' to '100' then show this...

I am using following but its not working:

 

<% if (Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men) =='50' to'100" )  { show this}

else { show this} %>

 

Any idea how to edit this statement to make it work?

 

Thanks!

 

 

1 Accepted Solution
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Hi @alik98709228 - you can try something like this:

<% if ( ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) >= 50 && ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) <= 100 )  {...} else {...} %>

 Cheers

Darren

View solution in original post

5 Replies
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Hi @alik98709228 - you can try something like this:

<% if ( ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) >= 50 && ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) <= 100 )  {...} else {...} %>

 Cheers

Darren

View solution in original post

alik98709228
Level 3
Level 3

Hi Darren,

 

I tried but I am keep getting syntax error:

 

<% if ( ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) >= 50 && ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) <= 100 ) {...} else {...} %>

 

Do you think 50 and 100 should be within quotation marks like '50' and '100'?

And there should be "else if" not just "else"?

 

Let me know.

 

Thanks!

 

Manoj_Kumar_
Community Advisor
Community Advisor
@alik98709228 If the return of ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) is a string then use the quotation marks. If the return data type is integer then keep it without quotations marks. it should be just If and else. Else if is required when you have multiple conditions
Darren_Bowers
Community Advisor
Community Advisor
Since you are converting the targetData attributes to numbers using Number() to perform a calculation (Men-Women)/Men then you need to compare the result of that to a number. If you add the quotes in, it will try to compare a number to a string. You also dont want an if else() statement in the since you only have two options (i.e. between 50 and 100 or everything else). To debug things like this, you can output the calculation part to the email as plain text and see what value you are getting. Things like targetData.Men = 0 will give you a divide by zero error so you might need to sanitise the results. Hope this helps. Darren
alik98709228
Level 3
Level 3
Hi Darren and Manoj, It worked. Thanks for your feedback!!!