Tell us what’s happening:
Describe your issue in detail here.
Hello! I was seeing if I am on the right track so far on this “Counting Cards” challenge. I have like 4 question marks out of the 7, but I want to see if my answer is making sense. Or if I’m accidentally doing the wrong thing, and the system is registering it as “right” Thank you!
**Your code so far**
var count = 0;
function cc(card) {
// Only change code below this line
switch(card) {
case 2:
count = 2 + 3;
return "5 Bet"
case 3:
count = 3 + 2;
return "5 Bet"
case 4:
count = 1 + 4;
return "5 Bet"
case 5:
count = 5;
return "5 Bet"
case 6:
count = 1 - 6;
return "5 Bet"
case 7:
case 8:
case 9:
return "0 Hold";
case 10:
count = 10 - 1;
return "9 bet"
case 'J':
count = 'J' - 1;
return "-1 Hold"
case 'Q':
count = 'Q' - 1;
return "-1 Hold"
case 'K':
count = 'K' - 1;
return "-1 Hold"
case 'Z':
count = 'Z' - 1;
return "-1 Hold"
case 'A':
count = 'A' - 1;
return "-1 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36 Edg/94.0.992.31
“You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table).”
The table provided tells you how much to change the global count value depending on the card passed into the function. It will either be +1, 0, or -1. This means you increase the value of count by one, or you decrease the value of count by 1, or you leave it as it is. This is a running count, so you want to either increase/decrease it by 1 based on its current value. Doing something like count = 2 + 3 does not take its current value into account. Also, count = 'J'-1 is nonsensical, you can’t subtract a number from a string.
“The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative.”
I don’t see where you are returning the current count. The current count is represented by the global variable count.
the previous version was better, there you were changing count, now remove all return statements from the switch, and make a separate part of the code where you determine the output based on the value of count
I think i know what you mean. I’m using an if statement, and i may have determined the output. This is what i have so far, but how can i put multiple return statements in an if statement?
var count = 0;
function cc(card) {
// Only change code below this line
if(card === count -- || count ++) {
return "5 Bet";
}
switch(card) {
case 2:
count ++;
break;
case 3:
count ++;
break;
case 4:
count ++;
break;
case 5:
count ++;
break;
case 6:
count ++;
case 7:
case 8:
case 9:
case 10:
count --;
case 'J':
count --;
case 'Q':
count --;
case 'K':
count --;
case 'Z':
count --;
case 'A':
count --;
}
return "Change Me";
First, you need to format your code correctly so we can read it. You need to wrap it in triple backticks. If you don’t know how to do this with your keyboard then click the </> button on this editor and it will put them in there for you.
About what you need to return, the instructions say:
" return a string with the current count"
The current count is kept in the count variable. So if you wanted to return the current number stored in that variable how would you do that? Don’t worry about the rest of your code at this point. Just show us here in this thread a simple return statement that returns the current number stored in count. I think we need to get this concept down first before helping you with the rest of your issues.