Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:意外的令牌案例(我找不到它)_Javascript - Fatal编程技术网

Javascript SyntaxError:意外的令牌案例(我找不到它)

Javascript SyntaxError:意外的令牌案例(我找不到它),javascript,Javascript,我不知道我在写这段代码时犯了什么错误。我对Java还是非常陌生;但我仔细检查了好几次,什么也没找到。 有人能找出什么毛病吗 var user = prompt("Welcome to Hogwarts! The sorting hat is on your head; are you brave, smart, nice, or cunning?").toLowerCase(); switch(user) { case 'brave': console.log("You wer

我不知道我在写这段代码时犯了什么错误。我对Java还是非常陌生;但我仔细检查了好几次,什么也没找到。 有人能找出什么毛病吗

var user = prompt("Welcome to Hogwarts! The sorting hat is on your head; are you brave,      smart, nice, or cunning?").toLowerCase();
switch(user) {
case 'brave':
    console.log("You were sorted into Gryffindor!");
    var gryffindor = prompt("Would you like to go to the common room, dormitory or the lake?").toLowerCase();
    if (gryffindor === 'common room' || gryffindor === 'dormitory') {
        console.log("After being given the password by a prefect, you tell it to the Fat Lady. Inside the Gryffindor Tower, you meet lots of new people!");
    } else {
        console.log("You go down to the lake, when you meet a Ravenclaw you met on the train. He's trying to show off.");
        var brave = prompt("Do you want to show off or ignore him?").toLowerCase();
        switch(brave) {
            case 'show off':
                var win = Math.random();
                if (win > 0.5) {
                console.log("You try doing the spell he's doing, but you don't do very well. Oh well, maybe being foolhardy isn't the best.");
                } else {
                console.log("You do another, more complicated spell that he can't do! Take that, pompous people!");
                }
                break;
            case 'ignore him':
                console.log("You walk away and find some new friends to talk with.");
                break;
            default:
                console.log("Hm, I didn't recognize what you said.");
    }
    break;
case 'smart':
    console.log("You were sorted into Ravenclaw!");
    var ravenclaw = prompt("Would you like to go to the common room or down to the lake?").toLowerCase();
    if (ravenclaw === 'common room') {
        console.log("You use the eagle knocker to knock on the door, and it gives you a riddle. You eagerly answer the riddle; you've heard much about Ravenclaw Tower.");
        var riddle = Math.random();
        if (riddle > 0.7) {
            console.log("You got the riddle wrong!");
        } else {
            console.log("You got the riddle right! You enter the common room and see hordes of intelligent, like-minded people. This is where you belong.");
        }
    } else {
        console.log("You go down to the lake, where you talk with some other first-years about the biology of the giant squid in the lake.");
    }
    break;
case 'nice':
    console.log("You were sorted into Hufflepuff!");
    console.log("You go to the common room, where some of the older kids are throwing a party. All the other Hufflepuffs are great, and you quickly make new friends.");
    break;
case 'cunning':
    console.log("You were sorted into Slytherin!");
    var snake = prompt("Do you want to go to the common room?)"
    var slytherin = prompt("You see another first year, Draco Malfoy walking up to the common room. He seems quite condescending towards others; do you want to talk to him?").toLowerCase();
    if (slytherin === 'yes' && snake === 'yes') {
        console.log("You start talking, but you want to leave the conversation almost immediately after its start. People like Draco are the reason Slytherin house has a bad name.");
    } else {
        console.log("You see Draco while walking and almost immediately turn in the opposite direction. Maybe it's best for you to go to the lake for now.");
    }
    break;
default:
    console.log("Hm, I didn't quite understand that. Maybe try again?");
};

好的,我知道了。非常感谢

console.log(“嗯,我没听清你说的话”)之后,你需要一个结束语
}
您需要修复这个
公共休息室?“
公共休息室?”)


工作演示:

需要进行两项更改。第26行,开关闭合支架缺失,第52行

// Code goes here

var user = prompt("Welcome to Hogwarts! The sorting hat is on your head; are you brave,      smart, nice, or cunning?").toLowerCase();
switch(user) {
case 'brave':
    console.log("You were sorted into Gryffindor!");
    var gryffindor = prompt("Would you like to go to the common room, dormitory or the lake?").toLowerCase();
    if (gryffindor === 'common room' || gryffindor === 'dormitory') {
        console.log("After being given the password by a prefect, you tell it to the Fat Lady. Inside the Gryffindor Tower, you meet lots of new people!");
    } else {
        console.log("You go down to the lake, when you meet a Ravenclaw you met on the train. He's trying to show off.");
        var brave = prompt("Do you want to show off or ignore him?").toLowerCase();
        switch(brave) {
            case 'show off':
                var win = Math.random();
                if (win > 0.5) {
                console.log("You try doing the spell he's doing, but you don't do very well. Oh well, maybe being foolhardy isn't the best.");
                } else {
                console.log("You do another, more complicated spell that he can't do! Take that, pompous people!");
                }
                break;
            case 'ignore him':
                console.log("You walk away and find some new friends to talk with.");
                break;
            default:
                console.log("Hm, I didn't recognize what you said.");

        }
    }
    break;
case 'smart':
    console.log("You were sorted into Ravenclaw!");
    var ravenclaw = prompt("Would you like to go to the common room or down to the lake?").toLowerCase();
    if (ravenclaw === 'common room') {
        console.log("You use the eagle knocker to knock on the door, and it gives you a riddle. You eagerly answer the riddle; you've heard much about Ravenclaw Tower.");
        var riddle = Math.random();
        if (riddle > 0.7) {
            console.log("You got the riddle wrong!");
        } else {
            console.log("You got the riddle right! You enter the common room and see hordes of intelligent, like-minded people. This is where you belong.");
        }
    } else {
        console.log("You go down to the lake, where you talk with some other first-years about the biology of the giant squid in the lake.");
    }
    break;
case 'nice':
    console.log("You were sorted into Hufflepuff!");
    console.log("You go to the common room, where some of the older kids are throwing a party. All the other Hufflepuffs are great, and you quickly make new friends.");
    break;
case 'cunning':
    console.log("You were sorted into Slytherin!");
    var snake = prompt("Do you want to go to the common room?");
    var slytherin = prompt("You see another first year, Draco Malfoy walking up to the common room. He seems quite condescending towards others; do you want to talk to him?").toLowerCase();
    if (slytherin === 'yes' && snake === 'yes') {
        console.log("You start talking, but you want to leave the conversation almost immediately after its start. People like Draco are the reason Slytherin house has a bad name.");
    } else {
        console.log("You see Draco while walking and almost immediately turn in the opposite direction. Maybe it's best for you to go to the lake for now.");
    }
    break;
default:
    console.log("Hm, I didn't quite understand that. Maybe try again?");
};

Java和JavaScript是两种截然不同的技术,尽管名称相似。这看起来是JavaScript。“我对Java还是个新手”--这是JavaScript,不是Java。你缺少嵌套的
开关(勇敢)
。开始使用或类似的方法。这更适合于