SarahH
06-26-2009, 06:03 PM
Hello All,
please could you help me as I am pulling my hair out with this one please could you look at my code and see where I am going wrong I am trying to write a program with the following :-
create an Array called fibArray which generates the first 20 fibonacci numbers
Then it should calculate the ratio by dividing each element of the first Array with the one before it and store these values in a second parrallel array called ratioArray
It should then find the first value of ratioArray that is closer to the golden ratio than 0.001m byt.
1.61803399 will be used as the value for the golden ratio.
finally it should display output in browser.
This is what I have currently:-
<html>
<body>
<script type="text/javascript">
var fibArray = new Array ();
document.write("<h4>The first 20 elements of the sequence are:</h4>");
for (i=0, j=1, k=0, fibArray =0; i<21; i++, fibArray=j+k, j=k, k=fibArray){
document.write(fibArray + ' ,');
}
for (i = 0; i < myfibArray.length; i++) document.write (myfibArray[i], ' - ', myfibArray[i] / 2, '<br>')
for (i = 0, j = 0; i < myfibArray.length; i++, j++) if (myfibArray[i] / 2 == 1.5)
document.write ('Line ', j, ' presents the value 1.5<br>')
var ratioArray= new Array();
for(i=0;i<fibArray.length;i++) {
var calculation = (myfibArray[i], ' - ', myfibArray[i] / 2, '<br>')
sequence.push(calculation);
}
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Please can someone help I have been trying to do this every night this week and am loosing hope that I will ever learn this language. Any help will be greatly appreciated.
Thankyou in advance
Sarah
please could you help me as I am pulling my hair out with this one please could you look at my code and see where I am going wrong I am trying to write a program with the following :-
create an Array called fibArray which generates the first 20 fibonacci numbers
Then it should calculate the ratio by dividing each element of the first Array with the one before it and store these values in a second parrallel array called ratioArray
It should then find the first value of ratioArray that is closer to the golden ratio than 0.001m byt.
1.61803399 will be used as the value for the golden ratio.
finally it should display output in browser.
This is what I have currently:-
<html>
<body>
<script type="text/javascript">
var fibArray = new Array ();
document.write("<h4>The first 20 elements of the sequence are:</h4>");
for (i=0, j=1, k=0, fibArray =0; i<21; i++, fibArray=j+k, j=k, k=fibArray){
document.write(fibArray + ' ,');
}
for (i = 0; i < myfibArray.length; i++) document.write (myfibArray[i], ' - ', myfibArray[i] / 2, '<br>')
for (i = 0, j = 0; i < myfibArray.length; i++, j++) if (myfibArray[i] / 2 == 1.5)
document.write ('Line ', j, ' presents the value 1.5<br>')
var ratioArray= new Array();
for(i=0;i<fibArray.length;i++) {
var calculation = (myfibArray[i], ' - ', myfibArray[i] / 2, '<br>')
sequence.push(calculation);
}
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Please can someone help I have been trying to do this every night this week and am loosing hope that I will ever learn this language. Any help will be greatly appreciated.
Thankyou in advance
Sarah