我需要有人帮我查看一些javascript代码,因为我';我收到一个说语法错误的错误

我需要有人帮我查看一些javascript代码,因为我';我收到一个说语法错误的错误,javascript,switch-statement,Javascript,Switch Statement,我需要有人看看这个代码。我是javascript的初学者,在我编写的代码中找不到错误 var user = prompt ("Are you a goblin, knight, troll, human, or wizard?").toLowerCase() var name = prompt("What is your name?").toLowerCase() var gender = prompt("Are you male or female?").toLowerCase() swit

我需要有人看看这个代码。我是javascript的初学者,在我编写的代码中找不到错误

 var user = prompt ("Are you a goblin, knight, troll, human, or wizard?").toLowerCase()
var name = prompt("What is your name?").toLowerCase()
var gender = prompt("Are you male or female?").toLowerCase()
switch(user) {
        case 'goblin':
            console.log("Hello, you are going to have a fun journey as a goblin");
            var meetAnt = prompt ("You run into a giant ant eater, you can attack or run. Do you choose to attack?").toLowerCase()
            if(meetAnt = yes) {
                console.log ("you stab him in the eye, but then he hits you with his trunk. You are injured");
                var finishAnt = prompt("you can either risk your life and finish him, or try to run away. Do you finish him?").toLowerCase()
                if(finishAnt = yes) {
                    return true;
                    console.log("congratulations you have killed the aint eater!")
                }
                else if(finishAnt = no) {
                    return false;
                    console.log("You run away and barley make it, you are badly hurt");
                    else {
                        console.log("sorry thats not an option")
                    }
                }
            }
            else {
                return true;
                console.log("You run past the ant eater and get to saftey. You are very lucky")
            }
            break;
        case 'knight':
            console.log("Hello, you are going to have a fun journey as a knight");
            var dayFight = prompt("You are versing the goblins in a fight, you need to choose how many days you go to fight(1-100). Remember if you choose too little days then you won't have stayed long enough to win the fight but if you stay to long you have more of a chance of dying or getting injured").toLowerCase()
            if(dayFight < 40) {
                return false;
                console.log("You did not fight enough days, which has resulted in your kingdome loosing the war to the goblins.");
            }
            else if(dayFight > 60) {
                return false;
                console.log("You have went to war to long and been seriously injured.");
            }
            else if(40<=dayFight=>60) {
                return true;
                console.log("You have been at war for the right amount of time. You have came out of the war with no injuries and you also have defieted the goblins!")
            }
            break;
        case 'troll':
            console.log("Hello, you are going to have a fun journey as a troll");
            var red = true;
            var green = true;
            var yellow = false;
            var blue = false;
            var houseRaid = prompt("You see four huts in the middle of the woods. You can raid two. There is a red hut, blue hut, yellow hut, and green hut. What is one color house that you want to raid?").toLowerCase()
            var doorPick = prompt("Do you want to enter throuhg the back door or front door?").toLowerCase()
            if(doorPick||houseRaid = "red"||"green" && "back door") {
                return true;
                console.log("You raided these houses and left before any villagers would see you");
            }
            else {
                return false;
                console.log("You raided those houses, but one of them was a booby trap and you are now captured");
            }
            break;
        case 'human':
            console.log("Hello, you are going to have a fun journey as a human");
            var reinforceFound = prompt("You know a storm is comming and you have to reinforce your hut, but you only have enough material to reinforce either your lower foundations or higher foundations. Which do you inforce? Higher or lower?").toLowerCase()
            if(reinforceFound = lower) {
                return false;
                console.log("The storms winds pushed down the top of your house and caved in your roof.");
            }
            else if(reinforceFound = higher) {
                return true;
                console.log("The storm did not do that much damage to your house due to your reinforced higher foundations. Good choice");
            }
            else {
                console.log("sorry but that is not an option. Pick either 'higher', or 'lower'")
            }
            break;
        case 'wizard':
            console.log("Hello, you are going to have a fun journey as a wizard");
            var blood = true;
            var dust = true;
            var wings = false;
            var mushrooms = false;
            var postion = prompt("You are working on a new healing potion but you do not know what you need to add to finish it. You have 4 ingrediants; blood, dust, wings, mushrooms. Pick one too add. (WARNING: Pick carefully because if you choose the wrong ingerdiant, then your potion will be ruined.)").toLowerCase()
            if(postion = wings || mushroom) {
                console.log("You picked a bad ingrediant and now your potion is ruined.");
            }
            else if(postion = dust || blood) {
                console.log("you picked the right ingrediant and your potion is okay")
            }
            else {
                console.log("sorry but that is not an option");
            }
            break;
        default:
            console.log("Sorry but that is not a character in the game");
};
var user=prompt(“你是地精、骑士、巨魔、人类还是巫师?”).toLowerCase()
var name=prompt(“你叫什么名字?”).toLowerCase()
var gender=prompt(“你是男性还是女性?”).toLowerCase()
交换机(用户){
“地精”一案:
log(“你好,你将作为一个地精进行一次有趣的旅行”);
var meetAnt=prompt(“你遇到一个巨大的食蚁兽,你可以攻击它,也可以逃跑。你选择攻击吗?”)。toLowerCase()
如果(meetAnt=yes){
console.log(“你刺伤了他的眼睛,但他用鼻子打了你。你受伤了”);
var finishAnt=prompt(“你可以冒着生命危险杀死他,也可以逃跑。你杀了他吗?”)。toLowerCase()
如果(finishAnt=yes){
返回true;
log(“恭喜你杀死了食客!”)
}
否则如果(finishAnt=否){
返回false;
log(“你逃跑了,成功了,你受了重伤”);
否则{
log(“对不起,这不是一个选项”)
}
}
}
否则{
返回true;
log(“你跑过吃蚂蚁的人,到了安全地带。你很幸运”)
}
打破
“骑士”一案:
log(“你好,你将作为一名骑士进行一次有趣的旅行”);
var dayFight=prompt(“你在一场战斗中对小妖精进行版本设置,你需要选择战斗的天数(1-100)。记住,如果你选择的天数太少,那么你就不会在战斗中停留足够长的时间,但是如果你停留太久,你就有更多的机会死亡或受伤”)。toLowerCase()
如果(日战<40){
返回false;
log(“你没有战斗足够的天数,这导致你的kingdome将战争输给了地精。”);
}
否则,如果(dayFight>60){
返回false;
log(“你已经参战很久了,而且受了重伤。”);
}
若否(4060){
返回true;
log(“你已经在战争中呆了很长时间了。你从战争中出来时没有受伤,你还玷污了地精!”)
}
打破
“巨魔”一案:
log(“你好,你将作为一个巨魔进行一次有趣的旅行”);
var red=真;
绿色变量=真;
黄色变量=假;
var蓝=假;
ValeHousAd=提示(“你在树林中间看到四个小屋。你可以袭击两个。有一个红色的小屋,蓝色的小屋,黄色的小屋和绿色的小屋。你想袭击的是什么颜色的房子?”)
var doorPick=prompt(“您想通过后门还是前门进入?”)。toLowerCase()
如果(选门| | | houseaid=“红色”| | |“绿色”和&“后门”){
返回true;
log(“你突袭了这些房子,在任何村民看到你之前就离开了”);
}
否则{
返回false;
log(“你突袭了那些房子,但其中一个是诱杀装置,你现在被抓获了”);
}
打破
“人类”案例:
log(“你好,你将作为一个人类进行一次有趣的旅行”);
var reinforcefind=prompt(“你知道暴风雨即将来临,你必须加固你的小屋,但你只有足够的材料加固你的较低地基或较高地基。你加固了哪一个?较高还是较低?”)。toLowerCase()
如果(发现加强件=较低){
返回false;
原木(“暴风雨的风推倒了你的屋顶,把你的屋顶吹塌了。”);
}
否则,如果(发现加强=更高){
返回true;
console.log(“由于你加固了更高的地基,暴风雨并没有对你的房子造成那么大的损坏。不错的选择”);
}
否则{
log(“对不起,这不是一个选项。请选择“更高”或“更低”)
}
打破
案例“向导”:
log(“您好,您将作为一名向导进行一次有趣的旅行”);
var血型=真;
var=true;
var wings=假;
var=false;
var postion=prompt(“您正在研制一种新的治疗药剂,但不知道需要添加什么才能完成。您有4种药剂:血液、灰尘、翅膀、蘑菇。请选择一种也添加。(警告:小心选择,因为如果您选择了错误的药剂,那么您的药剂将被销毁。))。toLowerCase()
如果(位置=翅膀| |蘑菇状){
log(“你选了一种坏的药剂,现在你的药剂坏了。”);
}
否则如果(位置=灰尘| |血液){
log(“你选择了正确的药剂,你的药剂也没问题”)
}
否则{
log(“对不起,这不是一个选项”);
}
打破
违约:
log(“对不起,这不是游戏中的角色”);
};

我正在网站www.codecademy.com上为课程编写此代码。这应该是游戏的一小部分。很抱歉,有这么多错误,如果错误来自,我无法再缩小范围。

语法错误是因为您在发布的代码的第18行缺少一个结束括号。这:

应该是:else {
} else {
if(meetAnt = yes) {
if(meetAnt == "yes") {
if(dayFight < 40) {
dayFight = parseInt(dayFight, 10);
else if(40<=dayFight=>60) {
else if(40 <= dayFight && dayFight <= 60) {
if(postion = wings || mushroom) {
if(postion == "wings" || postion == "mushroom") {
return true;
console.log("congratulations you have killed the aint eater!")
console.log("congratulations you have killed the aint eater!")
return true;