JBerm

06-01-2009, 11:45 PM

Hello I am new to using Javascript and have been trying to incorporate this equation into my if statement but cannot get it to calculate properly no matter which method I use. Here is the function as I have it worked out presently.

function Points()

{

Rating = document.Arena.Rating.value;

{

if (Rating <= 1500){

returnValue = Math.round((0.22 * Rating + 14) * 0.76)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^ (-0.00412 * Rating)) * 0.76)

};

document.Arena.Points2.value = returnValue

}

{

if (Rating <= 1500){

returnValue = Math.round((0.22 * Rating + 14) * 0.88)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^ (-0.00412 * Rating)) * 0.88)

};

document.Arena.Points3.value = returnValue

}

{

if (Rating <= 1500){

returnValue = Math.round(0.22 * Rating + 14)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^(-0.00412 * Rating))

};

document.Arena.Points5.value = returnValue

}

}

Now the problem I am having is in the else statement with the equation not executing correctly and giving a value of "0" since I am rounding. With the current equation and with a "Rating" of 1600 the "returnValue" should equal 465, but that is never the case. If I use Math.pow:

{

if (Rating <= 1500){

returnValue = Math.round(0.22 * Rating + 14)

};

else {

returnValue = Math.round(1511.26 / (Math.pow((1 + 1639.28 * 2.71828),(-0.00412 * Rating)))

};

document.Arena.Points5.value = returnValue

}

The result is 1.7133353971544615e+27 when again it should be 465. I know I'm missing something simple but with my lack of knowledge of javascript I'm just not seeing it.

Also I should note that this current project is a javascript conversion of my VB project I had made. Where the exponential value of (-0.00412 * Rating) is noted by the "^" and then executed as an exponential value. The result is the same in all of the else statements but for simplicity I singled out the last one as an example.

Thank You in advance for any help that can be given.

JB

function Points()

{

Rating = document.Arena.Rating.value;

{

if (Rating <= 1500){

returnValue = Math.round((0.22 * Rating + 14) * 0.76)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^ (-0.00412 * Rating)) * 0.76)

};

document.Arena.Points2.value = returnValue

}

{

if (Rating <= 1500){

returnValue = Math.round((0.22 * Rating + 14) * 0.88)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^ (-0.00412 * Rating)) * 0.88)

};

document.Arena.Points3.value = returnValue

}

{

if (Rating <= 1500){

returnValue = Math.round(0.22 * Rating + 14)

};

else {

returnValue = Math.round(1511.26 / (1 + 1639.28 * 2.71828 ^(-0.00412 * Rating))

};

document.Arena.Points5.value = returnValue

}

}

Now the problem I am having is in the else statement with the equation not executing correctly and giving a value of "0" since I am rounding. With the current equation and with a "Rating" of 1600 the "returnValue" should equal 465, but that is never the case. If I use Math.pow:

{

if (Rating <= 1500){

returnValue = Math.round(0.22 * Rating + 14)

};

else {

returnValue = Math.round(1511.26 / (Math.pow((1 + 1639.28 * 2.71828),(-0.00412 * Rating)))

};

document.Arena.Points5.value = returnValue

}

The result is 1.7133353971544615e+27 when again it should be 465. I know I'm missing something simple but with my lack of knowledge of javascript I'm just not seeing it.

Also I should note that this current project is a javascript conversion of my VB project I had made. Where the exponential value of (-0.00412 * Rating) is noted by the "^" and then executed as an exponential value. The result is the same in all of the else statements but for simplicity I singled out the last one as an example.

Thank You in advance for any help that can be given.

JB