Problem with card counting having errors

Tell us what’s happening:
I’m not understanding why it’s not working and passing the test. I got it mostly right, checked the answers and tweaked 2 things. It will not pass even though it appears to be the same as the answer. Any suggestion? Sometimes it’s just frustrating that you have to have the answer typed out exactly exactly as they do.

  **Your code so far**
let 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
}

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/102.0.0.0 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

HI @jeichler7 !
Welcome to the forum!

Add this console.log at the bottom of your code to see the issue

console.log(cc(2));

Hey. You forgot to add space in between the counter and the corresponding word.

I did that, still nothing.

I did that as suggested, it pops up as it you said, it pops up in the console, but doesnt give an explanation of any errors

You should be seeing this in the console.
Screen Shot 2022-06-07 at 3.00.55 PM

There is no space there.

That is what @udaaff and I are trying to point out to you

You added spaces here

and here?

What is your updated code?

Computers are extremely literal. You don’t need to reach the answer the same way as the test suite for these more complex challenges, but the output needs to be exactly what the tests are looking for. The computer has no way of knowing if ‘close’ is actually ‘close’ or ‘totally wrong’.

console.log won’t show error messages.
It’s job is to output a message to the console.

Developers use it to help them debug the issue.
The reason why I wanted you to add console.log(cc(2)); is so you can see the spacing issue for yourself.

It is an important tool you will use a lot in programming and will learn more in the next section of javascript.

Hope that helps!

1 Like