我是Javascript的新手,我正在学习有关开关语句的知识。我的代码试图运行两层的开关语句和验证数据。我想要的输出是让用户输入一个“是”或“否”,如果选择了“是”,那么它将通过开关语句,但是如果选择了“是”以外的任何内容,那么它将输出“太差了!”到控制台去。我有编译器错误,我不知道如何解决这个问题,因为我不完全理解javascript语法。
var user = prompt("Welcome to learning about exceptions with me, A-rod.
In this tutorial we will be learning about exceptions and what not
to do with them. Let's get started, shall we? ").toUpperCase();
switch(user){
case 'YES'
var user_1 = prompt("What's your name?");
switch(user_1) {
case 'Buster':
console.log("Hey, brother!");
break;
case 'Alex':
console.log("I've made a huge mistake.");
break;
case 'Steve':
console.log("Steve Holt!");
break;
default:
console.log("I don't know you!");}
break;
default:
console.log("too bad!");
}错误是
“期待”:‘而不是’变量‘“
和
“期待‘(结束)’而不是‘默认’”
发布于 2017-12-31 03:54:48
您在第一个开关语句中缺少了一个分号:
var user = prompt("Welcome to learning about exceptions with me, A-rod. In this tutorial we will be learning about exceptions and what not to do with them. Let's get started, shall we? ").toUpperCase();
switch(user){
case 'YES':
var user_1 = prompt("What's your name?");
switch(user_1) {
case 'Buster':
console.log("Hey, brother!");
break;
case 'Alex':
console.log("I've made a huge mistake.");
break;
case 'Steve':
console.log("Steve Holt!");
break;
default:
console.log("I don't know you!");}
break;
default:
console.log("too bad!");
}
发布于 2017-12-31 03:54:37
var user = prompt("Welcome to learning about exceptions with me, A-rod." +
"In this tutorial we will be learning about exceptions and what not" +
"to do with them. Let's get started, shall we? ").toUpperCase();
switch(user){
case 'YES':
var user_1 = prompt("What's your name?");
switch(user_1) {
case 'Buster':
console.log("Hey, brother!");
break;
case 'Alex':
console.log("I've made a huge mistake.");
break;
case 'Steve':
console.log("Steve Holt!");
break;
default:
console.log("I don't know you!");
break;
}
break;
default:
console.log("too bad!");
break;
}https://stackoverflow.com/questions/48039819
复制相似问题