【问题标题】:Switch Statement-JavaScript [closed]Switch 语句-JavaScript [关闭]
【发布时间】:2014-11-25 05:25:46
【问题描述】:

请参考下面JavaScript中的switch语句,同样不起作用。请指出错误。

function main(arg1){   
    switch(arg1) {
        case 'Jatin':
            alert('This is Jatin');
        break;
        case 'Vivek':
            alert('This is Vivek');
        break;
        case 'Vikas':
            alert('This is Vikas');
        break;
        default:
            alert('The name is not found');
    };
    main("Jatin");

【问题讨论】:

  • 请描述错误。
  • 你忘记了右括号
  • 查看 JavaScript 错误控制台的工作原理。如果能看到错误信息,对调试很有帮助。
  • 您的函数 main 缺少结尾 }
  • 谢谢。问题是右括号。非常感谢。

标签: javascript html


【解决方案1】:
function main(arg1){   
     switch(arg1) {
         case 'Jatin':
             alert('This is Jatin');
         break;
         case 'Vivek':
             alert('This is Vivek');
         break;
         case 'Vikas':
             alert('This is Vikas');
         break;
         default:
             alert('The name is not found');
     } // no semi colon
} // closing brace

main("Jatin");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 2021-04-11
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    相关资源
    最近更新 更多