我在w3cschool中的JS编程实战中遇到了一题JS条件判断算法的问题,是关于算21点的……问题如下我知道需要使用switch语句,大概的思路我画成了图var count = 0;
function cc(card) {
switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}
if (count>0){
return (count+" "+"Bet");}
else{
return (count+" "+"Hold");}
return "Change Me";
}早上自己写出来了……
2 回答
qq_王闯_0
TA贡献1条经验 获得超0个赞
var count = 0;
function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--
break;
}
return (count + ((count > 0) ? " Bet" : " Hold"));
// Only change code above this line
}
// Add/remove calls to test your function.
// 提示: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
// 使用三木运算符更有质量
添加回答
举报
0/150
提交
取消