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 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}
if(count > 0){
return count + "" + "Bet";
}else{
return count + "" + "Hold";
}
//return "Change Me";
// Only change code above this line
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; Infinix X5515 Build/O11019) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36.
It worked thanks alot
Pls
Can u clarify my understanding of *switch statement *
EXAMPLE
switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
count++;
break;
What is the count at each of the above numbers
Thanks again for your help
switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
For short code normally we use "if, if else, else’. When the code becomes larger and larger it is better practice to use 'switch-case ’ instead of lot of nested “if, else if, else” to be able to maintain a good overview!
In our case example an if-else will be enough to solve the challenge like this:
if (card >= 2 && card <= 6) {
card += 1;
}
else if {
//here same for the other values according to the challenge.
}
But the challenge is only to show how ‘switch-case’ works.
As far as black jack is concerned, i have not the slightest idea!