Counting Cards - Correct Output? Still Fails

Output seems correct for every scenario. I need to improve my testing skills ASAP. I cannot determine why this is failing. It is really similar to what the solutions recommend.

I have tried using the JSON.Stringify command to make the whole output a string vs just the ‘Hold’ and ‘Bet’ portions. I have done the return code section as a function and also by creating and changing a variable. I like the function method more and it works so that’s what my code uses.

I strongly suspect I have something very obvious in the output format that’s causing the fail. ‘A’ and ‘K’ inputs are strings, right? I cannot figure out how to get my code to accept just A. It has to be ‘A’. Is that the issue?

Any chance my love of console.log() is messing me up here?

  **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: 
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':

function action(count) {
if (count >0) {
  console.log(count+ ' Bet');
return (count+ ' Bet');
} else {
console.log(count+ ' Hold');
return (count+ ' Hold');

// Only change code above this line

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

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0

Challenge: Counting Cards

Link to the challenge:

What is this thing doing?

hmm, changing the function signatures and output behavior typically results in failing tests.

Hello Jeremy - thanks for taking a look!

That chunk of code is generating an output by combining the running count info with the recommended Hold/Bet action. I know it is super clunky but I think it works. I’ve been missing with the inputs just to see if I can make my code throw the wrong answer. What kills me is that I can feed it inputs that the test provides as examples and I get the output desired - yet it fails. Feels like I am doing some creative reading and my brain is skipping right past an issue somewhere.

You should only have one function, not two.

Examples when it fails:

"// running tests Cards Sequence 2, 3, 4, 5, 6 should return the string

5 Bet"

…my code returns 5 Bet when I use those inputs.

"Cards Sequence 10, J, Q, K, A should return the string

-5 Hold"

…my code returns -5 Hold with those inputs.

OK, that’s probably it then. I need to generate the output using a variable assignment somehow instead of the action(count) function I have right now.

Nope. You should use count to determine the output, but you should not have two functions.

I mean, your cc function doesn’t have an output, which si what is tested, so, no, it doesn’t work.

1 Like

I think that’s where I’m confused. Cheating and using the video solution - it uses the CC function to generate the running count. The output from the return statement then uses that count, but also another variable based on the count. Variable is ‘holdBet’.

You don’t need to create additional variables. You just need to put your two functions together instead of isolating half of the problem into a function that is never used by the tests.

Thanks for the help all.

that’s a way to solve it, but you don’t have a return statement in the cc function

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.