我不明白错误的含义。 "意外的标识符"。它并没有真正给我任何关于错误的信息。我之前收到此错误,我知道它可能是代码中的错误或我编写它的方式。请帮助。
<html>
<body>
<script type="text/JavaScript">
// Declare variables
var cardCat; // card category M=morning, A=afternoon, E=evening
var userInput; // user input of cards
var morCard = 0; // morning cards
var aftCard = 0; // afternoon cards
var eveCard = 0; // evening cards
var BR = "</ br>"
var ES = ""
// welcome user, start loop, and ask for card category
document.write("Welcome to Coffee Survey" +BR);
cardCat = prompt("Enter the category of the batch (M, A, or E) or enter Q to quit: " + ES);
userInput = prompt("Enter number of cards in the batch");
// start loop
while (cardCat != "Q") {
if(cardCat == "M")
{ morCard = morCard + userInput; }
else if (cardCat == "A")
{ aftCard = aftCard + userInput; }
else if (cardCat == "E")
{ eveCard = eveCard + userInput; }
};
// Display totals
document.write("Total # of morning cards: " + morCard + BR);
document.write("Total # of afternoon cards: " + aftCard +BR);
document.write("Total # of evening cards: " + eveCard + BR);
//End program
document.write("Thank you for using Coffee Survey");
</script>
</body>
</hmtl>
答案 0 :(得分:1)
javascript将是
while (cardCat != "Q") {
document.write("Enter number of cards in the batch");
if(cardCat == "M")
{mornCard = mornCard + userInput; }
else if(cardCat == "A")
{ aftCard = aftCard + userInput; }
else if(cardCat == "E")
{ eveCard = eveCard + userInput }
document.write("Enter category(M, A, or E) or enter Q to quit:);
};
你的代码看起来错误的是End If
的标记,所以正确的是,这是VBSCRIPT而不是javascript
// start loop
while cardCat != "Q" {
document.write("Enter number of cards in the batch");
If cardCat == "M" Then
mornCard = mornCard + userInput;
Else If cardCat == "A" Then
aftCard = aftCard + userInput;
Else If cardCat == "E" Then
eveCard = eveCard + userInput;
End If'correctly placed end if which is wrong in your code
}
document.write("Enter category(M, A, or E) or enter Q to quit:);
End while