Search code examples
javascriptlinear-equation

How can I fix Y at 2 if my X is more than 2000?


I have this line of equation in my JavaScript code.

Y= M*X + C
Y= -0.001*(X) + 4.1

My value for Y should be 2 at maximum, meaning my X input should be 2000 at max. However, I could not set the limit of X to 2000 as I would need the actual value of X for later calculation.

How can I fix Y at 2 if my X is more than 2000?

This is my code in javascript

document.getElementById("Result").innerHTML = (-0.001*(x) + 4.1);

Solution

  • <script>
    var Y = Math.max((-0.001*(Length * Width) + 4.1),4);
    <script>