有五種情況被接受。仍然是Java的新手,所以這是一個有點奇怪的例子。據我可以告訴(我已閱讀代碼至少兩次)它應該工作得很好,除非雙開關使它不起作用...我得到錯誤「SyntaxError:意外的標記案例」SyntaxError:意外的標記情況?
var shouldWeapon = String("sword");
var user = prompt("There's a duck in a pond. It likes fish. What do you do? Would you like to feed it, kill it, skin it, buy it, or fight it").toLowerCase();
switch(user) {
case 'feed it':
var whatHaveFood = prompt("What do you have for food?").toLowerCase();
switch(whatHaveFood) {
case 'pancakes':
console.log("Great! Ducks love their pancakes!");
break;
case 'muffins':
console.log("I'm sorry what? You carry muffins? Ducks LOOOOOOOOOOOVE MUFFINS LIKE OMIGOSH I LOVE MUFFINS MMMM M M MMMM MMM IN MY TUMMY.");
break;
case 'dormant spiders':
console.log("You decide not to give them to the duck. They're yours. Nobody gets your dormant spiders.");
break;
case 'apple':
console.log("OH BOY I LOVE APPLES -said no duck ever.");
break;
default:
console.log("The Duck doesn't like that. He curses you to the pits of hell and walks away.");
break;
};
break;
case 'kill it':
var whatHaveWeapon = prompt("What sort of weapon do you have?").toLowerCase();
if(shouldWeapon || whatHaveWeapon){
console.log("Why Aren't you using a sword? Why are you using a " + String(whatHaveWeapon) + ". They Suck!");
}else{
console.log("Good choice. The Duck is vanquished.");
}
break;
case 'skin it':
var tempCat = prompt("What temperature is the cat?");
if(tempcat > 4){
console.log("Don't skin ducks.");
}
else{
console.log("That's a freaking cold cat.");
}
break;
case 'buy it':
var buyDuckCost = Math.floor(Math.random()*5 + 1);
var buyDucky = ("How much money do you have?");
var missingMoney = buyDuckCost - buyDucky;
if(buyDucky >= buyDuckCost){
console.log("You have bought a duck! congratulations!");
}
else{
console.log("I'm sorry you don't have that much money. You still need" + String(missingMoney) + "$! The duck pulls out a gun and shoots you.");
break;
case 'fight it':
var Smickle = true
var Donkey = false
if(Donkey || Smickle){
console.log("YOU CAN'T FIGHT THE DUCK. THE DUCK IS TOO STRONG");
}
else{
console.log("Ummmm... this is the only accessible answer..... OMEGA GOOD JOB*Cute anime loli voice.*")
}
break;
console.log("What? You're going to do what with the duck?")
default:
}
據我所知,這應該起作用....
哇花花公子,給一些代碼格式:/,並解釋爲什麼它應該工作,並在那裏它不。 –
這不是Java。可能是JavaScript,這是一種非常不同的語言。 –
通常錯誤是伴隨着一個行號。你看/圍繞該線,找到錯誤並修復它。 –