错误的循环JavaScript

我对网页设计和Java语言还很陌生。设置我的第一个Web应用程序时,遇到了一个我不了解的错误。这一定是我认为Javascript可在网页中正常工作的某种方式,或者是我通常不了解循环的某种方式。

我正在尝试使用js突出表的最佳价值。只要文件在我的PC上本地运行,我就会生成随机值并按住刷新按钮,直到出现错误为止。为了调试目的,我现在也使用console.log函数,但是我仍然不明白这种情况的发生...

非常感谢有关在此实际上非常简单的代码中可能出什么问题的任何提示。

// Data engine 
switch(window.location.protocol) {
  case 'http:':
  case 'https:':
    //remote file over http or https

    break;
  case 'file:':
    // LEFT PLANE
    document.getElementById("counter").innerHTML =  Math.floor(Math.random() * 10001);
    document.getElementById("shift").innerHTML = "Night shift";
    document.getElementById("week").innerHTML = "";
    // RIGHT PLANE
    document.getElementById("mondaymorning").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("mondaylate").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("mondaynight").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("tuesdaymorning").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("tuesdaylate").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("tuesdaynight").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("wednesdaymorning").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("wednesdaylate").innerHTML = Math.floor(Math.random() * 10001);   
    document.getElementById("wednesdaynight").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("thursdaymorning").innerHTML = Math.floor(Math.random() * 10001);    
    document.getElementById("thursdaylate").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("thursdaynight").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("fridaymorning").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("fridaylate").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("fridaynight").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("saterdaymorning").innerHTML = Math.floor(Math.random() * 10001);
    document.getElementById("saterdaylate").innerHTML = "0";
    document.getElementById("saterdaynight").innerHTML = "0";
    document.getElementById("sundaymorning").innerHTML = "0";
    document.getElementById("sundaylate").innerHTML = "0";
    document.getElementById("sundaynight").innerHTML = Math.floor(Math.random() * 10001);
    break;
}

// Sum of week
document.getElementById("weektotal").innerHTML = Number(document.getElementById("mondaymorning").innerHTML) + 
   Number(document.getElementById("mondaylate").innerHTML) + 
   Number(document.getElementById("mondaynight").innerHTML) +
   Number(document.getElementById("tuesdaymorning").innerHTML) +
   Number(document.getElementById("tuesdaylate").innerHTML) +
   Number(document.getElementById("tuesdaynight").innerHTML) +
   Number(document.getElementById("wednesdaymorning").innerHTML) +
   Number(document.getElementById("wednesdaylate").innerHTML) +
   Number(document.getElementById("wednesdaynight").innerHTML) +
   Number(document.getElementById("thursdaymorning").innerHTML) +
   Number(document.getElementById("thursdaylate").innerHTML) +
   Number(document.getElementById("thursdaynight").innerHTML) +
   Number(document.getElementById("fridaymorning").innerHTML) +
   Number(document.getElementById("fridaylate").innerHTML) +
   Number(document.getElementById("fridaynight").innerHTML) +
   Number(document.getElementById("saterdaymorning").innerHTML) +
   Number(document.getElementById("saterdaylate").innerHTML) +
   Number(document.getElementById("saterdaynight").innerHTML) +
   Number(document.getElementById("sundaymorning").innerHTML) +
   Number(document.getElementById("sundaylate").innerHTML) +
   Number(document.getElementById("sundaynight").innerHTML) + 
   Number(document.getElementById("counter").innerHTML);

var formatter = new Intl.NumberFormat('de-be', {
 style: 'decimal',
 notation: 'compact',
});

document.getElementById("weektotal").innerHTML = formatter.format(Number(document.getElementById("weektotal").innerHTML));

// Best value of the week
var table = document.getElementsByTagName('table')[0];
var bestValue = 0;
var bestRow = 0;

for (var i = 1; i < 22; i++) {

   if (table.rows[i].childNodes[5].innerHTML > bestValue){
       bestValue = table.rows[i].childNodes[5].innerHTML;

       console.log(i);
       console.log(table.rows[i].childNodes[5].innerHTML);
       console.log(bestValue);
       bestRow = i;
   }
   else{
       console.log(i);
       console.log(table.rows[i].childNodes[5].innerHTML);
       console.log(bestValue);
   }
}

table.rows[bestRow].childNodes[5].classList.add('bestofweek');

print screen

评论