newtojavascript
Technical User
Hi
Can anyone help me with this javascript please
as you can see i have given it a far shot but just not getting the end result.
What i am trying to do is to list the outcome each time i click enter in a window like this
any help would be great as i am getting tired now after a week of trying
thanks
sue
aka (Newtojavascript)
xxx
Can anyone help me with this javascript please
as you can see i have given it a far shot but just not getting the end result.
What i am trying to do is to list the outcome each time i click enter in a window like this
Code:
16,14,4,5
2,10,1,11
8,9,10,9
1,1,1,1
0,0,0,0
Iterations taken: 4
any help would be great as i am getting tired now after a week of trying
thanks
sue
aka (Newtojavascript)
xxx
Code:
<HTML>
<HEAD>
<TITLE>
Ducci's Game
</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
//Write your functions here.
difference();
function difference() {
//Main program.
//Array which holds the numbers at the four corners of the square.
var numberArray = [16,14,4,5];//Edit this line to change the starting numbers
document.write(numberArray +'<BR>');//Write out array.
//Write the rest of the main program here.
var numberArray = [16,14,4,5];
var diffArray = new Array(4);
var count = 0;
var numLen = numberArray.length;
for (count = 0; count < numLen; count++)
{
if ((count + 1) == numLen)
{
diffArray[count] = numberArray[count] - numberArray[0];
alert("a " +numberArray[count] + " - " + numberArray[0] + " = " + diffArray[count]);
}
else
{
diffArray[count] = numberArray[count] - numberArray[count + 1];
alert("b " + numberArray[count] + " - " + numberArray[count + 1] + " = " + diffArray[count]);
}
}
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>