Skip to main content
Question

How can I add number ranges to Conditional statements?


Sally_Chan

How can I add number ranges to my Conditional statements? I’ve tried a lot of different formats and none seem to work.

It would be easy to just do >= 1 and <=3 as individual conditions, but I have a lot of ranges to add.

The conditions are 1-3, 4-6, 7-9, 10-12 … up to 24.

This topic has been closed for replies.

4 replies

Vishal_Ramawat

You can use divide by 3 logic to reduce the steps:


Maybe, you’ll have to use both If and Else, depending on the result you want.


Sally_Chan

Hmm I’m not sure if I understand or if this actually solves what I’m needing.

Essentially I have a component set named from 1-24. The interaction is that the numbers go up and down in sequence, and for every three, I need it to show another number when “confirmed”.

For example, if a user lands on any component in the 1-3 range, I have the prototype linked to a page that needs to show “6” for example. For components 4-6, show “7”. For components 7-9, show “8” and so on…


Vishal_Ramawat

Yupp, so basically you are just creating Multiples of 3 and using the result in conditional statement.
So, till 24, you’ll have 8 conditional statements. 1-3 gets covered in 3/3 = 1, 4-6 gets covered in 2, and so on.


tank666
  • 4873 replies
  • April 11, 2024
Figma Learn - Help Center

I don’t know why you are suggested to use the division operation. This is an unnecessary calculation.

As a result, you should end up with something like this:

if (numberVar >= 1 && numberVar <= 3) {
  // actions
}

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings