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==="+1";
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count==="-1";
break;
}
if (count==="+1"){
return "Bet";
}else{
return "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(7); cc('K'); cc('A');
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15.
switch (card)
{
case 2:
case 3:
case 4:
case 5:
case 6:
count===+1;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count===-1;
break;
}
if (count===+1){
return count + "Bet";
}else{
return count + "Hold";
}
ok that doesn’t really match the description of the problem though. So let me explain what +1 or -1 means in the challenge.
What they want is for you to count up or down depending on the card you see.
If you want to count up for example, you add 1.
If you want to count down , you subtract 1.
I’m assuming you know enough javascript to be able to code that…
If not, I can find some of the old challenges for you to help you learn that.
Actually I went though previous challenges trying yo find out what am I missing. But I got stuck.
so to add value of the count by one I return count++ and to count-- to subtract?
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";
}
The if statement above is basing what gets returned on the current card value instead of the current count value. Plus, it is only returning the count without the Hold or Bet concatenated to it.
As soon as a return statement is executed, the function immediately exits and stops processing any later code in the function.
No, you can use if statements, butlike you did with the Switch statement version, you must separate the increase/decrease logic of count from the logic which determines the actual string returned based on count. It is a two step process:
Increment or decrement the count variable based on the card value passed into the function.
Decide whether to return the count concatenated with " Bet" if count is greater than zero OR return count concatenated with " Hold" if count is not greater than zero.