一、
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);
}
}