Basic JavaScript - Counting Cards

I don’t know if this is a big deal or not but it’s bothering me. I’ve done research here and elsewhere but can’t seem to find a definitive answer.

I’ve passed the challenge but I can’t get the console to show the result of the function that matches the string in the tests section? Does anyone else have this issue?

console.log(cc(2), cc(3), cc(4), cc(5), cc(6));
console.log(cc(7), cc(8), cc(9));
console.log(cc(10), cc(‘J’), cc(‘Q’), cc(‘K’), cc(‘A’));
console.log(cc(3), cc(7), cc(‘Q’), cc(8), cc(‘A’));
console.log(cc(2), cc(‘J’), cc(9), cc(2), cc(7));
console.log(cc(2), cc(2), cc(10));
console.log(cc(3), cc(2), cc(‘A’), cc(10), cc(‘K’));

It seems like I’m not getting a cumulative increment/decrement result.

This shows the following in my console:

1 Bet 2 Bet 3 Bet 4 Bet 5 Bet         - instead of - "5 Bet"
5 Bet 5 Bet 5 Bet                     - instead of - "0 Hold"
4 Bet 3 Bet 2 Bet 1 Bet 0 Hold        - instead of - "-5 Hold"
1 Bet 1 Bet 0 Hold 0 Hold -1 Hold     - instead of - "-1 Hold"
0 Hold -1 Hold -1 Hold 0 Hold 0 Hold  - instead of - "1 Bet"
1 Bet 2 Bet 1 Bet                     - instead of - "1 Bet"
2 Bet 3 Bet 2 Bet 1 Bet 0 Hold        - instead of - "-1 Hold"
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14909.132.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Thanks for the reply. So, you mean the count is not resetting for each series? If so, I understand. In actuality I am getting a cumulative result for each card instead of each “hand”. Is there a way to write this so that you’re only getting one final result for each “hand”?

This kind of brings me to another question I’ve had throughout the function challenges. Where do return statements go? While I have been able to pass each challenge I can never see the function returns without using console log.

I will just address this part of your question.

Returns go nowhere if you don’t store them somewhere.
So you call a function and it returns say a number.
If you want to store it in a variable, you can, then use it later to do something else.
or you can call a function and have it return and pass that return to another function and have it return etc. eg:
console.log(add(multiply(subract(5,4), 6), 7));

I’m sorry , but now I’m confused again. Are you saying the test resets the count to zero for each function call series but the code itself is not?

Also, the challenge says "Do NOT reset count to 0 when value is 7, 8, or 9 but when we don’t my log shows “5 Bet”. This would be the wrong answer if I were really using the “program”. I feel dumb, what am I missing…

I guess I’m imagining this being used at a blackjack table. Wouldn’t you want the “program” to just tell you, based on what showing, “5 bet” or “0 Hold”, instead of a string for each card in the function call series?

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