Hello everyone,
I have a function that is suppose to reduce the fraction. Unfortunately it is not reducing. My script is a kids math program that will have the user add, subtract, mutliply and divide fractions. Right now I am calling the function only in the mutiplication portion of the script. Can someone tell me where I am going wrong and what I might do to correct it?
The function:
[code]
function reduce(numerator,denominator) {
var gcd = function gcd(a,b) {
return b ? gcd(b, a%b) : a;
};
gcd = gcd(numerator,denominator);
return [numerator/gcd, denominator/gcd];
}
Where I am using it in the code:
[code]
function multiply() {
if(document.quizform.arithmetic[0].checked)
maxValue=10;
else {
if(document.quizform.arithmetic[1].checked)
maxValue=30;
else {
maxValue=60
}
}
n1=ranom(maxValue);
d1=random(maxValue);
n2=ranom(maxValue);
d2=random(maxValue);
An=(n1 * n2);
Ad=(d1 * d2);
reduce(An, Ad); <—————Here
numAns=(An + “/” + Ad);
Answer=window.prompt( n1 + “/” + d1 + ” * ” + n2 + “/” + d2 + ” = “, 0);
ans();
}
If you need more of the program let me know.