Card counter JavaScript

I have tried this in many different ways…they are starting to scramble my brain. Can someone please help me. What I have now is word by word how it is on the help video…and still its wrong.

Your code so far


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++;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}
var holdbet = "Hold"
if ( count > 0) {
holdbet = "Bet"
 }
return count + "" + holdbet;
// 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/83.0.4103.116 Safari/537.36 Edg/83.0.478.61.

Challenge: Counting Cards

Link to the challenge:

If you add

console.log(cc());

at the end of your code, I think that you’ll be able to see the issue. You have a missing space between the number and the Hold/Bet string.

2 Likes

Hello~!

I wrapped a function call in a console.log - take a look at what you are returning. Does something seem off here? :slight_smile:

2 Likes

I have and it comes up 1Bet, I changed the code and am still getting the same thing…I couldn’t find a missing space.

  }
  if (count > 0) {
    return count + " Bet";
  } else {
    return count + " Hold";
  }

This is what I replaced it with. This is what is on the hint…still does not work. can you give me a more direct hint.
Thanks

When I make that change, your code passes for me. Can you post your full code?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

here is my full code

type or paste code here
```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++;
  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');

In the above version, you don’t have the spaces you added in this snippit.

I don’t understand. My first code had a completely different end and you said I had missing space. It was exactly like the watch video hint. So I chanced it to be be exactly like the hint version…neither are working. I cant understand it. The tree that are now the if statement are completely that same. I don’t see the spaces. Please help.

This

is not this

Your snippet and your code you posted don’t agree.

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++;
  break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
  count--;
  break;
} 
var holdbet = "Hold"
if (count > 0) {
  holdbet = "Bet"
} 
  return count + "" + holdbet;
}



  // Only change code above this line
}

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

You still are missing a space. This looks like your first version.

There is no space in between those two quotes.

oh…im sorry…I see it now… I’ve been staring at this whole thing for two hours and I’m brain dead. Thank you

1 Like

It happens to all of us :slight_smile:

I didn’t know I needed a space after the " … so that you.
:laughing:

if you need a space in the final result, you need to add it somewhere, they do not magically appear

I’m sure you will remember next time!

Happy Coding!