html – Website not responding – I think due to javascript code-ThrowExceptions

Exception or error:

I’m trying to make a game in javascript and display it on my website, but the website isn’t responding anymore. The internet connection is just fine.

Here is the code where I think it went wrong:

$(function(){

  init();
  console.log("Main Init Called")

});

function InitFilesRanksBrd() {

  var index = 0;
  var file = FILES.FILE_A;
  var rank = RANKS.RANK_1;
  var sq = SQUARES.A1;

  for(index = 0; index < BRD_SQ_NUM; ++index) {
    FilesBrd[index] = SQUARES.OFFBOARD;
    RanksBrd[index] = SQUARES.OFFBOARD;
  }

  for(rank = RANKS.RANK_1; rank <= RANKS.RANK_5; ++rank) {
    for(file = FILES.FILE_1; rank <= FILES.FILE_E; ++file) {
      sq = FR2SQ(file,rank);
      FilesBrd[sq] = file;
      RanksBrd[sq] = rank;
    }
  }

  console.log("FilesBrd[0]:" + FilesBrd[0] + " RanksBrd[0]:" + RanksBrd[0]);
  console.log("FilesBrd[SQUARES.A1]:" + FilesBrd[SQUARES.A1] + " RanksBrd[SQUARES.A1]:" + RanksBrd[SQUARES.A1]);
  //console.log("FilesBrd[SQUARES.C5]:" + FilesBrd[SQUARES.C5] + " RanksBrd[SQUARES.C5]:" + RanksBrd[SQUARES.C5]);
  console.log(FilesBrd);
  console.log(RanksBrd);

}

function init(){
  console.log("init() called");
  InitFilesRanksBrd();
}
How to solve:

In the inner for, the variable that you are comparing is rank, not file. It should be:

for(file = FILES.FILE_1; file <= FILES.FILE_E; ++file)

Because the rank variable isn’t incrementing until the loop content end, but the loop content doesn’t end because of the inner loop.

Leave a Reply

Your email address will not be published. Required fields are marked *