Am I on the right track so far on this challenge?

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

Challenge: Counting Cards

Link to the challenge:

A few things to think about:

“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.

Thank you for responding! But I’m still confused about what you mean lol

how do you add or substract 1 to a variable?

you would do something like

var stone = 1 - 3;

no, that is giving to stone the value of -2, you are not decreasing the value of a variable

i see that is interesting

let a = 7;
__?__
console.log(a); // 6

what’s the missing step in this code?
note that a = 6 is not valid, as it needs to work also if you don’t know the value of a

a -= 6; i think it might be?

Look at the exercises called “Increment a number with JavaScript” and “Decrement a number with JavaScript”

Let’s try it…
image

no, it seems it doesn’t work. It is removing 6 from the value of the variable

ah, would it be something like

a- -

that’s better, so now you can write the code to decrease or increase count in the rigth places

Thanks! So this is what i have so far. but it looks like it appears the same

switch(card) {

  case 2:

    count ++;

    break;

  case 3:

    count ++;

    break;

  case 4:

    count ++;

    break;

  case 5:

    count ++;

    break;

  case 6:

    count ++;

    return "5 Bet"

  case 7:

  case 8:

  case 9:

    return "0 Hold";

  case 10:

    count --;

    return "9 bet"

  case 'J':

    count --; 

    return "-1 Hold"

  case 'Q': 

    count --;

    return "-1 Hold"

  case 'K':

  count --;

    return "-1 Hold"

  case 'Z':

    count --;

    return "-1 Hold"

  case 'A':

  count --;

  return "-1 Hold"

} 

  return "Change Me";

Look at the exercise called " Multiple Identical Options in Switch Statements"

you need to return based on the value of count so you need to separate the logic for changing count and the logic for the return statement

I’m… not sure how to do that lol. Anyway, this is what i have so far. i used the stuff that you and @AngelHeeley said

switch(card) {

case 2:

case 3:

case 4:

case 5:

case 6:

return "5 Bet"

case 7:

case 8:

case 9:

return "0 Hold";

case 10:

case ‘J’:

case ‘Q’:

case ‘K’:

case ‘A’:

return “-5 Hold”;

}

return “Change Me”;

now that’s worse

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.