Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - JScript
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

JScript

 Post Reply Post Reply
Author
VBScript View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2004
Location: United Kingdom
Status: Offline
Points: 219
Post Options Post Options   Thanks (0) Thanks(0)   Quote VBScript Quote  Post ReplyReply Direct Link To This Post Topic: JScript
    Posted: 23 March 2005 at 12:30pm
Can any one help me comment the following code please?

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

//Maximum number of disks
var MAXHEIGHT = 8;

//Number of selected disks
var ndisk;

//Timer variable
var timer = null;

//Move from array (0-255)
var mvfrom = new Array(255);

//Move to array (0-255)
var mvto = new Array(255);

var mv, imv;

//Tower Array
var tower = new Array(3);

var h = new Array(3);

var spc = "        ";

//Set disk name array
var dname = new Array(
"|",
"111",
"22222",
"3333333",
"444444444",
"55555555555",
"6666666666666",
"777777777777777",
"88888888888888888");


function init() {
  // Initallize function

   if (!timer) {
      //If timer is not set, set s to the selected number of disks
      s = document.formHanoi.disk.options[document.formHanoi.disk.selectedIndex].value;
    
      if (s == "random") {
         //If s is set to random then get the date
         now = new Date();

         ndisk = parseInt(now.getTime() / 1000) % 8 + 1;
        
         //delete the now variable and its content
         delete now;
      }
   else ndisk = s;
     
      //number of moves = 0
      mv = 0;

      //Call hanoi function
      hanoi(0, 2, 1, ndisk);

      for (i = 0; i < 3; i++)

      tower = new Array(MAXHEIGHT);

      for (i = 0; i < ndisk; i++)

      tower[0] = ndisk - i;

      h[0] = ndisk;

      h[1] = h[2] = 0;

      imv = 0;
     
      document.formHanoi.display.value = gentower();
     
      timer = window.setTimeout("gennexttower()", document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
   }
}

function stop() {
   if (timer) {
   
      //If the timer is not empty then clear it
      //and set to nothing
      window.clearTimeout(timer);
      timer = null;
   }
}


function hanoi(from,to,buf,nmv) {
   if (nmv > 1) {
      hanoi(from, buf, to, nmv - 1);
      mvfrom[mv] = from;
      mvto[mv++] = to;
      hanoi(buf, to, from, nmv - 1);
   }
   else {
      mvfrom[mv] = from;
      mvto[mv++] = to;
   }
}

function gennexttower() {
   tower[mvto[imv]][h[mvto[imv]]++] = tower[mvfrom[imv]][--h[mvfrom[imv]]];
   document.formHanoi.display.value = gentower();
   if (++imv < mv)
      timer = window.setTimeout("gennexttower()", document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
   else {
      for (i = 0; i < 3; i++)
      delete tower;
      timer = null;
       }
}
function gentower() {
   s = " \n";
   for (i = MAXHEIGHT - 1; i >= 0; i--) {
      for (j = 0; j < tower.length; j++) {
      len = i < h[j] ? tower[j] : 0;
      width = MAXHEIGHT - len;
      s += " " + spc.substring(0, width) + dname[len] + spc.substring(0, width);
      }
      s += "\n";
   }
   return s+"=======================================================";
}
-->
</script>



Edited by VBScript - 23 March 2005 at 12:35pm
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 23 March 2005 at 6:30pm
what's the problem? There are comments in there.
Back to Top
VBScript View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2004
Location: United Kingdom
Status: Offline
Points: 219
Post Options Post Options   Thanks (0) Thanks(0)   Quote VBScript Quote  Post ReplyReply Direct Link To This Post Posted: 24 March 2005 at 2:40am
Only half of it is commented. I dont understand the rest, i am not an expert in Javascript I hoped someone could help finish the commenting.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.