If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need some help with my assignemnt.

I have done some but cannot figure out hot to set the player’s position to the number of the square at the same index in the connected squares array (from
specialSquaresArray to connectedSquaresArray).
I have structured English:

call the function rollDie and store the return value as the player’s score
write out the score
add the score to the player’s position
write out a message saying what square the player is on
call the function findIndexOf with suitable arguments to look for the index
of the player’s position in the special squares array and store the value
returned
if the index is not -1
set the player’s position to the number of the square at the same index
in the connected squares array
write out a message saying what square the ladder has taken the player
to
end if
write out a line break

But I just cannot figure out hot to access those arrays.
Any help appreciated.

HTML Code:

<HTML><HEAD><TITLE>
Snakes and Ladders
</TITLE><SCRIPT LANGUAGE = "JavaScript">
/*
* M150 TMA03 2010J Q4.
* Program to simulate a one-player version of 'Snakes and Ladders'
*/
//PROVIDED FUNCTIONS -- you do not need to change these
/*
*imitates a normal 6-sided die, by returning a random whole number between 1 and 6 inclusive.
*/
function rollDie()
{
return Math.floor(Math.random() * 6) + 1;
}
/*
*searches for a number in a number array.
*
*function takes two arguments
* the number to search for
* the number array to search
*function returns the array index at which the number was found, or -1 if not found.
*/
function findIndexOf(number, numberArray)
{
var indexWhereFound = -1;
for (var position = 0; position < numberArray.length; position = position + 1)
{
if (numberArray[position] == number)
{
indexWhereFound = position;
}
}
return indexWhereFound;
}
//ARRAYS that represent the board -- you do not need to change these
//array of special squares
var specialSquaresArray = [1,7,25,32,39,46,65,68,71,77];
//array of corresponding squares the player ascends or descends to
var connectedSquaresArray = [20,9,29,13,51,41,79,73,35,58];
var planszaArray=80;
//VARIABLES used -- you do not need to change these
//the square the player is currently on
var playersPosition;
//play is initially at START
playersPosition = 0;
//what they score when they roll the die
var playersScore;
//the index of the player's position in the special squares array or -1
var indexOfNumber;
//MAIN PROGRAM
while (playersPosition < planszaArray)
{
rollDie();
playersScore = rollDie();
document.write('Score : ' + playersScore);
playersPosition = playersPosition + playersScore;
document.write(' Square : ' + playersPosition + '<BR>');
findIndexOf(playersPosition,specialSquaresArray);
indexOfNumber = findIndexOf(playersPosition,specialSquaresArray);
{
if (indexOfNumber != -1)
-------------------It must go here-------------------------
}
}
//TODO add code here for parts (iii), (iv)(b), (v), and (vi)
</SCRIPT></HEAD><BODY></BODY></HTML>