この割り当てのエラーを確認するには、私は助けが必要です。このスクリプトを実行すると私のインターネットブラウザがクラッシュします!私はこのスクリプトを完全に自分で書いたので、間違っているかもしれません!これは、配列を使用して月を出力するためにループを使用する学校の割り当てです。JavaScript:プログラムがクラッシュするのはなぜですか?
PS:私がブレーク/コンティニューコードを作成するまで、プログラムはうまくいった!これに
document.write("I skipped March with a continue statement”.”);
:あなたが適切にあなたの引用を閉じていない
document.write("I skipped March with a continue statement”.");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment 6: Steph Hussar</title>
<script type="text/javascript">
// Variable Declaration
var monthArray = new Array();
monthArray[0]="January";
monthArray[1]="February";
monthArray[2]="March";
monthArray[3]="April";
monthArray[4]="May";
monthArray[5]="June";
monthArray[6]="July";
monthArray[7]="August";
monthArray[8]="September";
monthArray[9]="October";
monthArray[10]="November";
monthArray[11]="December";
// Using the for loop
document.write("<h4>Using the for loop</h4>");
for(var count =0 ; count < 12 ; count++)
{
document.write(monthArray[count] + "<br />");
}
// Using the while loop
document.write("<h4>Using the while loop</h4>");
var count = 0;
while (count < 12)
{
document.write(monthArray[count] + "<br />");
count++;
}
// Using for in loop
document.write("<h4>Using for in Loop</h4>");
for(index in monthArray)
{
document.write(monthArray[index] +"<br />");
}
// Using the Break
document.write("<h4>Using the break when the month of March is found</h4>")
for(count = 0 ; count < 12 ; count++)
{
if (count == 3)
{
break;
}else{
document.write(monthArray[count] + "<br />");
}
}
document.write("I broke out of the loop!");
// Using the Continue
document.write("<h4>Using the continue when the month of March is found</h4>")
for(count = 0 ; count < 12 ; count++)
{
if (count == 2)
{
continue;
}else{
document.write(monthArray[count] + "<br />");
}
}
document.write("I skipped March with a continue statement!");
</script>
</head>
<body>
</body>
</html>
セミコロンが各javascript文の最後にあることを確認してください。特にdocument.write文が重要です。 –
宿題なので、答えは教えてくれません。しかし、ヒントとして、個々のループをコメントアウトしてから、クラッシュの原因を見つけだしてから、ループのどの部分が原因で発生するのかを特定してください。 –
@JohnPick - 実際には、セミコロンはjavascriptでは必須ではありません。 – mrtsherman