Tell us what’s happening:
Hello,
Question about switch:
Is switch actually operating as a loop?
I was surprised seeing the solution beause with regard this code below, I was expecting the following;
1 iteration: cc(2) => count = 1 and then the function return “1 Bet”
2 iteration: cc(3) => count = 2 and then the function return “2 Bet”
etc…
here it seems that the function return in one time the total count and Bet or Hold.
Sor fo an example with the following:
cc(2); cc(3); cc(4); cc(5); cc(6);
It returns once “5 Bet”.
So it seems to me that switch is acting like a loop where all the followings
cc(2); cc(3); cc(4); cc(5); cc(6);
are called in the function before entering the IF condition.
or does it return 5 times:
1 Bet
2 Bet
3 Bet
4 Bet
5 Bet
and the exercise just accept this as a solution?
Thanks for your precision.
Your code so far
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";
}
}
cc(2); cc(3); cc(4); cc(5); cc(6);
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";
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
.
Link to the challenge:
unable to post link