Coop Coop - 1 month ago 8
Javascript Question

Javascript algebra/algorithm maths

I'm trying to do do some algebra in jQuery/javascript based on some conditions and known variables but I'm not good enough at maths or javascript to understand how to write it.

So here's the conditions:

var w1 = h1/1.98

var w2 = h2/0.6355

h1 = h2

w1 + w2 = 1367


I'm not 100% sure but I think there may be enough info here to find out what w1, w2, h1 and h2 are. Does anyone know how I can create this calculation?

Answer

Here is the solution with variables as you need:

function algebra(c1, c2) {
  /* Given these equations
  w1 = h1/c1
  w2 = h2/c2
  h1 = h2
  w1 + w2 = 1367; */

  var w1 = 1367 * c2 / (c1 + c2), h1 = w1 * c1;
  return {w1:w1, w2:1367-w1, h1:h1, h2:h1};
}
Comments