FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.

Home Page:https://fcc.asia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no need to use break

Mineocat opened this issue · comments

Challenge Selecting from many options with Switch Statements has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function myTest(val) {
  var answer = "";
  // 请把你的代码写在这条注释以下
  
  switch(val){
    case 1:
      return "alpha";
    case 2:
      return "beta";
    case 3:
      return "gamma";
    case 4:
      return "delta";
  }
  
  // 请把你的代码写在这条注释以上
  return answer;  
}

// 你可以修改这一行来测试你的代码
myTest(1);

为什么要强制使用break呢

为什么要强制使用break呢

因为不使用的话,程序会继续向后接着逐步执行