|
Ummm...I think you need to go back and take pre-algebra again.
If you do:
x1 = 0;
x2 = 4;
x3 = 0;
x4 = 0;
Then you do:
y = (x2-x1) + (x3-x2) + (x4-x3);
you will be doing:
y = (4 - 0) + (0 - 4) + (0 - 0)
which is
y = (4) + (-4) + 0
which is, correctly:
y = 0
*********
In any case, just going one step further into elementary algebra, why not SIMPLIFY this equation:
y = (x2-x1) + (x3-x2) + (x4-x3);
which becomes:
y = x2-x1+x3-x2+x4-x3;
which becomes
y = x2-x2 + x3-x3 - x1 + x4
which becomes
y = 0 + 0 - x1 + x4
which becomes
y = x4 - x1
In other words, the values entered for x2 and x3 *DO NOT MATTER*. The end result will only depend on x1 and x4.
Me thinks you have much much bigger problems than just your JavaScript. Which is actually working correctly.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
|