0

I have some code that I was using to generate a calculation from two inputs but am having trouble generating the result I need.

I have two inputs (let's call them input1 and input 2). When you enter in a value, it calculates it based on the following:

(input1 x 0.156$) x ( (input2 x 15 seconds) x 4.2) x 12 months

My original code is as follows:

var calculation = function() {
  var input1 = document.getElementById('people').value;
  var input2 = document.getElementById('stories').value;
  var result = Math.floor(input1 * 0.2 * input2 * 30);
  document.getElementById('result').innerHTML = result;
  return false;
}

It's the var result that I'm having difficulty changing (the code above was for a different calculation). Any help would be greatly appreciated!

Freddy
  • 13
  • 3
  • The code looks fine to me, but how are you calling this function? – Niet the Dark Absol May 18 '16 at 14:19
  • technically it works but it's a different calculation than what I need now. I tried var result = Math.floor(input1 * 0.2 * (input2 * 30) * 4.2 ) * 12; but it spits out a very large result, so I think it's incorrect. – Freddy May 18 '16 at 14:22
  • Well your "new" calculation is basically adding an extra `* 4.2 * 12` to the mix, making roughly a 50x increase to the previous number... – Niet the Dark Absol May 18 '16 at 14:26
  • I noticed that, too. I clarified in the thread below a little more specifically what I'm trying to achieve. – Freddy May 18 '16 at 14:39

2 Answers2

0

It looks to me that you are not implementing your formula correctly, try changing it to:

var result = Math.floor((input1 * 0.156) * ((input2 * 15)*4.2)*12);

It also will be good to tell us what 4.2 stands for.

Here's a working JSFiddle

0

Try this: var result = Math.floor((parseInt(input1) * 0.2) * (parseInt(input2) * 30));

by converting the input1 & input2 to numeric

Umar Waliyullah
  • 529
  • 6
  • 17