我不明白这个错误是什么意思。 “意外的标识符”。它并没有真正给我任何有关错误的信息。我以前遇到过这个错误,我知道这可能是代码或我编写代码的方式中的错误。请帮忙。
<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>
最佳答案
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
关于javascript - 意外的标识符修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31276330/