0

Formula is (val x 0.5) + 50 = result, but if result is greater then 200, then override result to 150

My if is if (val > 200) { result = 150 }

2 Answers2

0

If you just need a function:

function doSomething(val)
 {
   var result = val *.5 + 50;

   if ( result > 200 )
 {
    result = 150;
  }

return result;
}

In one line I suppose it would be:

var result = (val*.5) + 50 > 200 ? 150 : (val*.5) + 50;
Avitus
  • 15,640
  • 6
  • 43
  • 53
0

I'm assuming if val<= 200, the result will be the real result.

    var result = (val * 0.5) +50;

    result = result>200?150:result;
CalebC
  • 922
  • 11
  • 24