Counting Cards - what am I doing wrong?

Working on the Counting Cards code. The following code fails the test. I don’t know what is wrong. I have spent hours looking at it and re-typing it.

let count = 0;

function cc(card) {
  // Only change code below this line

let change = 0;
let bet = "";
switch (card) {
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    change = 1;
    break;
  case 7:
  case 8:
  case 9:
    change = 0;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    change = -1;
    break;
}
count = (count + change);
if (count > 0){
  bet = " Bet";
}else if (count <= 0) {
  bet = " Hold";
}
  return (count, bet) ;
  // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

now, if I put the following just before the final return:

console.log(count, bet);

The output before running the tests is:

1 Bet
2 Bet
2 Bet
1 Bet
0 Hold

Which would seem correct. I don’t understand what I am doing wrong.

Please help.

This isn’t what you are supposed to return.

The instructions state:
" 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. The current count and the player’s decision (Bet or Hold ) should be separated by a single space."
What am I supposed to return if not the count and “Bet” or “Hold”?

You are returning a tuple of two values, not a single string with the current count and the Hold/Bet string.

You are only returning the value of bet which is the string " Bet" or " Hold" because JavaScript will return the last value of a series of values separated by commas between ( and ).

For example:

const a = 'this is a';
const b = 'this is b';
const c = 'this is c';
const d = (a, b, c);
console.log(d); // displays 'this is c'

JavaScript does not yet have tuples, but they are on the horizon.

Doh! (smacks head in frustration)

OK, I combined the 2 values into a string and returned the string. and it worked. I added:

returnString = count + bet;
  return (returnString) ;

Even though the output looks identical in the console, I guess it’s different (2 separate values) at the code level.

Thank you!!!

Not sure what you mean. If you console.log each call to the function (using the code you posted originally):

let count = 0;

function cc(card) {
  // Only change code below this line

let change = 0;
let bet = "";
switch (card) {
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    change = 1;
    break;
  case 7:
  case 8:
  case 9:
    change = 0;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    change = -1;
    break;
}
count = (count + change);
if (count > 0){
  bet = " Bet";
}else if (count <= 0) {
  bet = " Hold";
}
  return (count, bet) ;
  // Only change code above this line
}

console.log(cc(2));
console.log(cc(3));
console.log(cc(7));
console.log(cc('K'));
console.log(cc('A'));

the following gets logged to the console. See no count value.

 Bet
 Bet
 Bet
 Bet
 Hold

Don’t include this.
case 7:
case 8:
case 9:
change = 0;

That’s where the issue is coming from. It counted 0, hence not relevant.

remove your “change”.
“count” is given already

There is no need for that case, but including it is harmless.

Thanks for the replies, everyone. I’m not sure I understand what you mean in some cases. So I’ll start with @RandellDawson :

if I use this code (which fails):

let count = 0;

function cc(card) {
  // Only change code below this line

let change = 0;
let bet = "";
let returnString = ""
switch (card) {
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    change = 1;
    break;
  case 7:
  case 8:
  case 9:
    change = 0;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    change = -1;
    break;
}
count = (count + change);
if (count > 0){
  bet = " Bet";
}else if (count <= 0) {
  bet = " Hold";
}
console.log(count,bet)
  return (count, bet) ;
  // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

my console shows:
1 Bet
2 Bet
2 Bet
1 Bet
0 Hold

If I use this code (which passes) and print to the console before the final return

let count = 0;

function cc(card) {
  // Only change code below this line

let change = 0;
let bet = "";
let returnString = ""
switch (card) {
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    change = 1;
    break;
  case 7:
  case 8:
  case 9:
    change = 0;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    change = -1;
    break;
}
count = (count + change);
if (count > 0){
  bet = " Bet";
}else if (count <= 0) {
  bet = " Hold";
}
returnString = count + bet;
console.log(returnString)
  return (returnString) ;
  // Only change code above this line

I get:

1 Bet
2 Bet
2 Bet
1 Bet
0 Hold

They look identical to me

@G-Coding , @JeremyLT , you’re both right, that code isn’t needed, but it also isn’t causing any issues.

Console.logging values separated by commas is different than returning values surrounded by ( and ) and separated by commas.

What I was talking about is the value returned from the function.