function within a function doesnt work
<p>I have the following program but when i try to encrypt word JAVASCRIPT it seems like function 'rotateToPosition' within function 'encrypt' doesnt work. The answer i get is Xjavascript. It displays symbol character X at the beggining as i want it and it changes  letters from plainArray to cipherArray but it doesent shift them. The answer i'm looking for is Xzqlqishyfj. Does anyone know i do wrong?
Thanks.</p>

<pre><code>&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt; 
Alberti's Disks
&lt;/TITLE&gt;

&lt;SCRIPT LANGUAGE = "JavaScript"&gt;



    // array of upper case letters
    var plainArray = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    // array of lower case letters
    var cipherArray = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];

//The function shift all elements to the rignt

function right(letterArray)
{
    var ShiftToRightArray = new Array (26); //creates new array
    for (var count = 0; count &lt; 25; count++) // checks every argument in the array
        {
            ShiftToRightArray[count + 1] = letterArray[count]; //assigns one argument from letterArray to index from new array increased by one
        }
     ShiftToRightArray[0] = letterArray[25]; //assigns last argument from letterArray to first index in new array
     return ShiftToRightArray; //returns value of new array
}


//The function simulates the rotation of a cipher alphabet

function rotateToPosition(signalCharacter, indexCharacter, plainAlphabet, cipherAlphabet)
{
    var rotateArray = new Array (26);
    rotateArray = cipherAlphabet;
    while (rotateArray[0] != indexCharacter)
        {
            rotateArray = right(rotateArray);
        }
    return rotateArray;
}

//Function to encrypt given word

function encrypt(plainText, signalCharacter, indexCharacter, plainAlphabet, cipherAlphabet)

{
   // rotate array to signal character position
   rotateToPosition(signalCharacter, indexCharacter, plainAlphabet, cipherAlphabet)
   //will hold the results of the encrpytion until it can be appended to encryptedString
   var encryptedString = signalCharacter;
   for (var count = 0; count &lt; plainText.length; count++)
   {
       var singleLetter = plainText.charAt(count);
       var i = plainAlphabet.indexOf(singleLetter);
       encryptedString = encryptedString + cipherAlphabet[i];
   }

   return encryptedString;
}

function testTask02()
{
    window.alert(right(cipherArray));
}

function testTask03()
{
    window.alert(rotateToPosition('A', 'g', plainArray, cipherArray));
}

function testTask04()
{
//encrypts word JAVASCRIPT using X as signal character and n as index character
   window.alert(encrypt('JAVASCRIPT', 'X', 'n', plainArray, cipherArray));
}

&lt;/SCRIPT&gt;

&lt;/HEAD&gt;

&lt;BODY&gt;



    &lt;FORM NAME = "Form"&gt;

    &lt;STRONG&gt;SIMULATING ALBERTI'S DISKS&lt;BR&gt;&lt;/STRONG&gt;

    &lt;P&gt;
    &lt;INPUT TYPE = "button" NAME = "task02Button"  VALUE ="Test Task 2"
            ONCLICK = " testTask02() ;"&gt;    
    &lt;/P&gt;
    &lt;P&gt;
    &lt;INPUT TYPE = "button" NAME = "task03Button"  VALUE ="Test Task 3"
            ONCLICK = " testTask03() ;"&gt;    
    &lt;/P&gt;
    &lt;P&gt;
    &lt;INPUT TYPE = "button" NAME = "task04Button"  VALUE ="Test Task 4"
            ONCLICK = " testTask04() ;"&gt;    
    &lt;/P&gt;
    &lt;/FORM&gt;


&lt;/BODY&gt;

&lt;/HTML&gt;
</code></pre>
