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

How to use greater than '>' to compare to data values

Avatar

Avatar
Give Back
Level 2
alik98709228
Level 2

Likes

3 likes

Total Posts

28 posts

Correct Reply

0 solutions
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 3
Boost 1
View profile

Avatar
Give Back
Level 2
alik98709228
Level 2

Likes

3 likes

Total Posts

28 posts

Correct Reply

0 solutions
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 3
Boost 1
View profile
alik98709228
Level 2

03-03-2021

Hello,

 

I am using greater than sign '>" to compare two data values and show a value.

For instance, there are two data fields: Men and Women. Men value is '10', and Women value is '5':

 

Men

10

Women

5

 

1: I am using following syntax but its not working:

 

<% if (targetData.Men > targetData.Women) {%>

show this...

 

2: And this is not working either: if (Men - Women) > '30' (%>:

<% if (targetData.Men - targetData.Women) > '30' {%>

show this...

 

Any idea?

 

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

80 likes

Total Posts

277 posts

Correct Reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

80 likes

Total Posts

277 posts

Correct Reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile
Darren_Bowers
MVP

03-03-2021

Hi @alik98709228 - you don't say what the data type of your attributes are so I'll assume since it isn't working that they are Strings

You can try something like this:

<% if (Number(targetData.Men) > Number(targetData.Women)) { %> ... <% } else {} %>
or 
<% if (parseInt(targetData.Men) - parseInt(targetData.Women)) > 30) { %> ... <% } else {} %>

https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/

Cheers

Darren

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 50
Employee
Sukrity_Wadhwa
Employee

Likes

154 likes

Total Posts

910 posts

Correct Reply

35 solutions
Top badges earned
Give Back 50
Validate 1000
Validate 500
Validate 250
Validate 100
View profile

Avatar
Give Back 50
Employee
Sukrity_Wadhwa
Employee

Likes

154 likes

Total Posts

910 posts

Correct Reply

35 solutions
Top badges earned
Give Back 50
Validate 1000
Validate 500
Validate 250
Validate 100
View profile
Sukrity_Wadhwa
Employee

10-03-2021

Hi @alik98709228,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!