Basic JavaScript - Counting Cards

Tell us what’s happening:
Count and string are not being returned. Why not?

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 += 1;
break;
case 7:
case 8:
case 9:
count += 0;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
count -= 1;
break;
}

return count + (count > 0 ? " Bet" : " Hold");

}
cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);


**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0</code>

**Challenge:**  Basic JavaScript - Counting Cards

**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

If you want to see the return on console, you need to console.log the calls to function.

console.log(cc(2), cc(3), cc(7), cc('K'), cc('A'));

Or you can declare a result variable and put inside the return items.
So you can do a console.log(result) inside the function.

Return, didn’t show any console log results, only returns a value from the called function.

Hi,

Thank you for following up with me. I typed out a response, but I received the following error message from the forum:

Sorry, new users can only put 2 links in a post.

I am not sure what 2 links the error message refers to…

Anyway, I tried both ways, and I got the following error messages:

Tests

  • Passed: Your function should return a value for count and the text (Bet or Hold) with one space character between them.

  • Passed: Cards Sequence 2, 3, 4, 5, 6 should return the string 5 Bet

  • Failed: Cards Sequence 7, 8, 9 should return the string 0 Hold

  • Passed: Cards Sequence 10, J, Q, K, A should return the string -5 Hold

  • Failed: Cards Sequence 3, 7, Q, 8, A should return the string -1 Hold

  • Failed: Cards Sequence 2, J, 9, 2, 7 should return the string 1 Bet

  • Passed: Cards Sequence 2, 2, 10 should return the string 1 Bet

Passed: Cards Sequence 3, 2, A, 10, K should return the string -1 Hold

And:

Tests

  • Passed: Your function should return a value for count and the text (Bet or Hold) with one space character between them.

  • Passed: Cards Sequence 2, 3, 4, 5, 6 should return the string 5 Bet

  • Failed: Cards Sequence 7, 8, 9 should return the string 0 Hold

  • Passed: Cards Sequence 10, J, Q, K, A should return the string -5 Hold

  • Failed: Cards Sequence 3, 7, Q, 8, A should return the string -1 Hold

  • Failed: Cards Sequence 2, J, 9, 2, 7 should return the string 1 Bet

  • Passed: Cards Sequence 2, 2, 10 should return the string 1 Bet

Passed: Cards Sequence 3, 2, A, 10, K should return the string -1 Hold

Thank you for your help.

Ken

It’s hard to catch a break around here, and this proves it.

Thank you for helping me with that. I just remembered than line-by-line editors exist. I can’t remember the freemium one I use to use. Any recommendations.

Again, thank you, Mr. Dawson.

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