为什么只有我的交换机列表的第一种情况正常工作?

时间:2015-02-21 05:56:29

标签: javascript

对于我的生活,我无法弄清楚它有什么问题。当我运行这个脚本时,第一个'STAY'案例就可以了。运行任何其他情况会给我一个错误(undefined不是一个函数)。

通过我的JS检查器,它看起来没问题。谷歌搜索它和我遇到的同样问题的其他人都被告知他们的休息使用不正确或不在那里。根据我所学到的,所有语法都适合我。将它与样本“游戏”进行比较,看起来与它们的表现非常相似。我究竟做错了什么?!感谢您的帮助

var user = prompt("You see God. Do you want to STAY, PUNCH HIM, or CRY?").toUpperCase();

switch(user) {
case 'STAY':
    var curious = prompt("Are you a curious person?").toUpperCase();
    var insight = prompt("Are you an insightful person?").toUpperCase();
    if (curious === "YES" && insight === "YES") {
        console.log("Maybe it was a good idea to stay and speak to him");
    } else if (curious === "YES" || insight === "YES") {
        console.log("Well, maybe you can scrunge up something to say");
    } else {
        console.log("Why would you stay if you have nothing intelligent to say?");
    }
    break;
case 'PUNCH HIM':
    var strong = prompt("Are you ridiculously stronger than God?").toUpperCase();
    var fast = prompt("Are you faster than a minute man?").toUpperCase();
    if (strong === "YES" && fast === "YES") {
        console.prompt("You still dead, but not as dead as you would've been");
    } else if (strong === "YES" || fast === "YES") {
        console.prompt("One ain't good enough, homie");
    } else {
        console.prompt("Slow and weak? Bad choice, dag");
    }
    break;
case 'CRY':
    var convincing = prompt("Are you superbly convincing with crying?").toUpperCase();
    var female = prompt("Are you a female?").toUpperCase();
    if (convincing === "YES" && female === "YES") {
        console.prompt("You'll prolly be ok, boo");
    } else if (convincing === "YES" || female === "YES") {
        console.prompt("Hope you're a female");
    } else {
        console.prompt("You dead!");
    }
    break;
default:
    console.prompt("Answer the question with the supplied answers");

}

1 个答案:

答案 0 :(得分:3)

使用console.log代替console.prompt