Hello,
I have been trying to work at this script for about 3 days now but can’t seem to work out what I want to do. What I want to do is put two numbers (a, and b)into two fields, and then find two numbers that multiply to get “a” and those SAME two numbers must add to get “b”.
Now, I got the part where I was able to factor ONE number, and show all of it’s factors (Look at the script below.)I cleaned it up to make it look easy to read and to test it out for yourself. I got some help from a friend to help me write it.
BUT, my problem is, is that Im not able to put in the TWO numbers, in TWO different fields, and then calculate the factors for the first number. Then take the factors and figure out which one will both MULTIPLY to give me “a” and ADD to give me “b”.
[B]An example would be like this:
[I]What two numbers multiply together to give me 12, and add together to give me 7?
Well, the factors of 12 are (12,1) (6,2) and (3,4).
And if 3 and 4 add together AND multiply together they give me 12, and 7.
Also, how can I include negatives into all of this? [B]Example:
[I]What two numbers multiply to give me (-99) and add to give me (2).
Answer would be outputted as: (-9, 11).
The answers of the final numbers that Multiply and Add to give me those two numbers would lastly be outputted to a final field.
Anways if you misunderstand me, I’ll try my best to explain! Thank you very much! And I’ll try my best to understand you!
Thanks,
AJ Phinney :p
PS – Here’s the code I’m currently using.
[CODE]
<HTML>
<HEAD>
<script language=”JavaScript”>
<!–
function SymError()
{
return true;
}
window.onerror = SymError;
//–>
</script>
<script language=”javascript”>
function doit(){
a=document.factors.num.value;
checker=Math.sqrt(a);
output=””;
for (x=1; x<=checker; x++)
{
c=a/x;
d=Math.floor(c);
if(c==d){
output = output + “(” + x + “,” + c + “)” + “n”;
}
}
document.factors.worksp.value= “Factors Are:n” + output;
}
</script>
</HEAD>
<form name=”factors”>
<strong>Factor A Number </strong><br>
<input name=”num” type=”text” size=”15″><br>
<input type=”button” name=”bt1″ value=”CALCULATE” onClick=”doit()”>
<input type=”reset” value=”CLEAR”><br>
<strong>Result</strong><br>
<textarea name=”worksp” wrap=”hard”></textarea>
</form>
</center>
</BODY>
</HTML>