ssjskipp

01-22-2006, 10:12 PM

Well, I was trying to make this program for my PSP, and I started in Flash, then converted it to PHP, and finally I need to convert it to Javascript. All my program does it take a user-entered number, and give all the factors (multiplication) for it, in the form of a table (collective string). In PHP, it works fine, in fact here it is:

http://www.sticktoons.net/ssjskipp/random/GCF.php

But in Javascript (which I have no expierence with), it messed up...here's the script:

<form name="my_form">

<p>

<input name="num" type="text" id="num" value="0">

<input type="button" name="button" value="Get the GCF"><p>

</form>

<script language="javascript">

gcf = 1

g = 1

num = document.my_form.num

a = num

b = num

i_max = num/2

str = ""

i = 0

cur_fact = 0

document.my_form.button.onclick ="get_gcf()"

document.alert(document.my_form)

function get_gcf(){

num = document.my_form.num

if (Number(num) == num){

gcf = 1

g = 1

a = num

b = num

i_max = num/2

str = ""

i = 0

cur_fact = 0

}

if (gcf == 1){

document.write("<hr>Your Greatest Common Factors:<br/><table border=\"2\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>Factor</td><td>Factor</td><td>Added Together</td></tr>")

while (g > 0){

if (g == 1) {

cur_fact = (i*a)

if (cur_fact == num) {

document.write("<tr><td>".i."</td><td>".a."</td><td>".(i+a)."</td></tr>")

}

g = 2

} else if (g == 2) {

if (a>1 && i<i_max) {

a--

g = 1

} else if (a<=1 && i<i_max) {

b--

i++

a = b

g = 1

} else if (i>=i_max) {

g = 0

}

}

}

document.write("</table>")

}

}

}

</script>

Can anyone help? (I have NO idea what in the pie I did wrong, BTW)

http://www.sticktoons.net/ssjskipp/random/GCF.php

But in Javascript (which I have no expierence with), it messed up...here's the script:

<form name="my_form">

<p>

<input name="num" type="text" id="num" value="0">

<input type="button" name="button" value="Get the GCF"><p>

</form>

<script language="javascript">

gcf = 1

g = 1

num = document.my_form.num

a = num

b = num

i_max = num/2

str = ""

i = 0

cur_fact = 0

document.my_form.button.onclick ="get_gcf()"

document.alert(document.my_form)

function get_gcf(){

num = document.my_form.num

if (Number(num) == num){

gcf = 1

g = 1

a = num

b = num

i_max = num/2

str = ""

i = 0

cur_fact = 0

}

if (gcf == 1){

document.write("<hr>Your Greatest Common Factors:<br/><table border=\"2\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>Factor</td><td>Factor</td><td>Added Together</td></tr>")

while (g > 0){

if (g == 1) {

cur_fact = (i*a)

if (cur_fact == num) {

document.write("<tr><td>".i."</td><td>".a."</td><td>".(i+a)."</td></tr>")

}

g = 2

} else if (g == 2) {

if (a>1 && i<i_max) {

a--

g = 1

} else if (a<=1 && i<i_max) {

b--

i++

a = b

g = 1

} else if (i>=i_max) {

g = 0

}

}

}

document.write("</table>")

}

}

}

</script>

Can anyone help? (I have NO idea what in the pie I did wrong, BTW)