首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript嵌套开关语句

Javascript嵌套开关语句
EN

Stack Overflow用户
提问于 2017-12-31 03:49:41
回答 2查看 2.9K关注 0票数 1

我是Javascript的新手,我正在学习有关开关语句的知识。我的代码试图运行两层的开关语句和验证数据。我想要的输出是让用户输入一个“是”或“否”,如果选择了“是”,那么它将通过开关语句,但是如果选择了“是”以外的任何内容,那么它将输出“太差了!”到控制台去。我有编译器错误,我不知道如何解决这个问题,因为我不完全理解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!"); 
 }

错误是

“期待”:‘而不是’变量‘“

“期待‘(结束)’而不是‘默认’”

EN

回答 2

Stack Overflow用户

发布于 2017-12-31 03:54:48

您在第一个开关语句中缺少了一个分号:

代码语言: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!"); 
 }

票数 3
EN

Stack Overflow用户

发布于 2017-12-31 03:54:37

代码语言: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;
     }
break;
default:
    console.log("too bad!"); 
    break;
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48039819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档