Counting Cards exercise

I found a guide for this exercise which offers two possible solutions but interestingly, even after verifying that my code looks exactly like one of the solutions offered, it still doesn’t pass any of the tests… Anyone have any idea’s why this might be? Here’s my code:

function cc(card) {
  // Only change code below this line
  switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
  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');```

Have you tried to console.log your output? You have a minor issue that is fast to see if you log the output.

Do you mean have I tried running the code in the console? (Sorry, I’m still learning how to talk about this stuff.) I just did try it and it works, actually.



at the end of your code.

Ok, thank you. I just played with it a little more and found that it’s not working correctly after all. As it has been only incrementing and decrementing by 1 even if I pass in multiple arguments (as the tests do).

You only pass one argument at a time, and you only go up or down by one at a time. That is correct.

The output is what you should be looking at.

Does that look right?

I’m sorry, where are you suggesting I put the console.log?

Right there where I put it in the picture, at the very bottom of the code in your editor.

In that case (passing one argument at a time, going up or down by one at a time) it’s already working perfectly.

That’s outside of the area in which I’m supposed to write my code ( where it says ‘change only above this line’).

The count incrementing is working correctly. The output (return value) is wrong.

You can add debugging output outside of your function body, that is perfectly fine.

1 Like

Here’s a screenshot of my console running this code. How can the count incrementing be working right and the output be wrong?

Look at the string being returned. Look at the requested output. They are not exactly, perfectly, identically, character-for-character the same.

Ok, I added that line of code and still failing all tests

Just adding a logging statement outside of your function isn’t going to change what your function does.

You need to look at what the log statement shows your function returning.
The requested output looks like

0 Hold

Your output does not look like this.

So then why did you tell me to just add the log statement?

So you could look at the output. Did you look at the output? Did you compare it to the requested output? Do you see the small, single character difference?



0 Hold

Your output is different than the required output.

Added the space, thanks

Huzzah! :tada: