1

If I want to limit a value between a min and max, today I use somthing like that :

if (level > 100) level = 100;
if (level < 0) level = 0;

I'm quite sure that there should be a more elegant/fastest method to do that. If yes, what could it be ?

gonzalle
  • 51
  • 4

1 Answers1

1

You could use this:

var level = level > 100 ? 100 : (level < 0 ? 0 : level)

It's called Conditional Statement, see this for more informations...

Matheus Cuba
  • 2,068
  • 1
  • 20
  • 31