你好我浏览了与JavaScript相关的问题,但没有结果。我想做的很简单;我知道该怎么做,但由于某种原因它无法正常工作。这是我遇到问题的代码:playersScore = rollDie();document.write('Score: ' + playersScore);playersPosition = playersScore + playersPosition;document.write(', Square: ' + playersPosition);indexOfNumber = findIndexOf(playersPosition, specialSquaresArray);if (indexOfNumber != -1) { document.write(', Ladder to Square: ' + connectedSquaresArray[indexOfNumber] + '<BR>'); playersPosition = connectedSquaresArray[indexOfNumber]; indexOfNumber = -1;}// end of question(iii)// start of question(iv)(b)while (playersPosition < 80) { playersScore = rollDie() document.write('Score: ' + playersScore) playersPosition = playersPosition + playersScore document.write(', Square: ' + playersPosition) indexOfNumber = findIndexOf(playersPosition, specialSquaresArray) if (indexOfNumber != -1) { document.write(', Ladder to Square: ' + connectedSquaresArray[indexOfNumber]); playersPosition = connectedSquaresArray[indexOfNumber]; } document.write('<BR>');这是浏览器中的结果:得分:4,正方形:4得分:4,正方形:8得分:2,平方:10得分:1,平方:11得分:2,平方:13得分:5,平方:18得分:4,平方:22得分:1,平方:23得分:5,平方:28得分:3,正方形:31得分:5,平方:36得分:3,正方形:39,阶梯到正方形:51得分:4,平方:55得分:6,平方:61得分:6,平方:67得分:1,正方形:68,阶梯到正方形:73得分:1,平方:74得分:3,正方形:77,阶梯到正方形:58得分:5,平方:63得分:1,平方:64得分:4,正方形:68,阶梯到正方形:73得分:6,平方:79得分:6,平方:85第一行是玩家的“先走”(得分:4,方块:4),但我需要紧随其后的那一行(得分:4,方块:8)打破下面的线,但是无论我在哪里放置不会这样做。是前几行有问题还是在while循环开始时有问题?我真的不明白!非常感谢您的帮助。提前谢谢了。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 如果找不到梯子,只需写换行符:if (indexOfNumber != -1) { document.write(', Ladder to Square: ' + connectedSquaresArray[indexOfNumber] + '<BR>'); playersPosition = connectedSquaresArray[indexOfNumber]; indexOfNumber = -1;}else { document.write('<BR>');} (adsbygoogle = window.adsbygoogle || []).push({});
08-25 16:04