1. if...else if 语句
function judgment(n) {
if(n === 0) {
return "a"
} else if(n === 1) {
return "b"
} else if(n === 2) {
return "c"
} else if(n === 3) {
return "d"
} else if(n === 4) {
return "e"
} else {
return "f"
}
}
2. switch 语句
function judgment(n) {
switch (n) {
case 0:
return "a"
case 1:
return "b"
case 2:
return "c"
case 3:
return "d"
case 4:
return "e"
case 5:
return "f"
default:
return "g"
}
}
3. 通过Object存储
function judgment(n) {
const judgmentObj = {
0: "a",
1: "b",
2: "c",
3: "d",
4: "e",
5: "f"
}
return judgmentObj[n]
}