js之switch语句练习

一、 

function myTest(val) {
var answer = "";
// Only change code below this line
switch(val){
    case "a":
        answer="apple";
    break;
    case "b":
        answer="bird";
    break;
    case "c":
        answer="cat";
    break;
    default:
    answer="stuff"
}


// Only change code above this line
return answer;
}

// Change this value to test
myTest(1);

 二、把串联的 if/if else 语句改成 switch 语句。

function myTest(val) {
var answer = "";
// Only change code below this line

if (val === "bob") {
answer = "Marley";
} else if (val === 42) {
answer = "The Answer";
} else if (val === 1) {
answer = "There is no #1";
} else if (val === 99) {
answer = "Missed me by this much!";
} else if (val === 7) {
answer = "Ate Nine";
}

// Only change code above this line
return answer;
}

// Change this value to test
myTest(7);

 

function myTest(val) {
var answer = "";
// Only change code below this line
switch (val) {
    case "bob":answer = "Marley";
        // code
        break;
    case  42:answer = "The Answer";
        break;
    case 1:answer = "There is no #1";
        break;
    case 99:answer = "Missed me by this much!";
    break;
    default:
    answer = "Ate Nine";
    
      // code

// Change this value to test
myTest(7);

}
}
  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值