一般来说,我是javascript和编码的新手。
我试图在画布上以随机坐标绘制一系列圆圈,并且我试图根据其他一些值来确定圆圈组的fillStyle,这些值并非如此为简单起见包括在这里谁能告诉我为什么我在这里得到看似无限循环的东西?
for (var counter = 1; counter <= 30; counter++) {
var xCenter = 154;
var yCenter = 270;
var accuracyMod = (300 + 800) * 0.0013;
var xMax = (xCenter + (100 - 50) * accuracyMod);
var xMin = (xCenter - (100 - 50) * accuracyMod);
var yMax = ((yCenter + (100 - 50) * accuracyMod)) - (100 - 50);
var yMin = ((yCenter - (100 - 50) * accuracyMod)) - (100 - 50);
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
console.log(randomIntFromInterval(xMin, xMax), (randomIntFromInterval(yMin, yMax)));
var stroke = "color";
var fill = "color";
var intense = 85;
for (var counter = 1; counter <= 7; counter++) {
if (intense < 5) {
stroke = "#fffdfc";
fill = "#fffdfc";
} else if (intense <= 20) {
stroke = "#ffebd7";
fill = "#ffebd7";
} else if (intense <= 40) {
stroke = "#ffae5f";
fill = "#ffae5f";
} else if (intense <= 60) {
stroke = "#ff7402";
fill = "#ff7402";
} else if (intense <= 80) {
stroke = "#e25610";
fill = "#e25610";
} else if (intense <= 95) {
stroke = "#b84452";
fill = "#b84452";
} else {
stroke = "#ac3f65";
fill = "#ac3f65";
}
}
}
答案 0 :(得分:3)
是的,因为你在外部和内部循环中使用counter
作为迭代变量。内部循环每次都会在counter
处离开8
。外循环测试永远不会失败,因此它将继续。
使用两个单独的计数器变量。另外,缩进代码以反映其结构。