Javascript Lab Build a Card Counting Assistant

I passed this Card Counting Assistant Lab, however, two of the test criteria for this lab are as follows:

4. After the cards 2, 3, 4, 5, then calling cc(6) should return the string 5 Bet.

6. After the cards 10, "J", "Q", "K", then calling cc("A") should return the string -5 Hold.

However, my code is as follows, and when logging in console, it simply returns the initial card plus or minus 1. Why did I pass these tests are am I misunderstanding the instructions? Is it meant to assume as if there were an iteration over the cards/the count?


let count = 0;

let cc = (card) => {
    if (card >= 2 && card <= 6) {
        count++;
    } 
    else if (card >= 7 && card <= 9) {
        count = count;
    } 
    else if (
        card === 10 || 
        card === 'J' || 
        card === 'Q' || 
        card === 'K' ||
        card === 'A'
    ) { 
        count--;
    }

    if (count > 0) {
        return count + ' Bet';
    } else if (count <= 0) {
        return count + ' Hold';
    }; 
};

Could you link to the lab?

1 Like

Yes, edited! Link here as well.

please share which function calls you are using to test

I am using the function calls as they are in the tests (i.e., cc(6) and cc(‘A’).

if you ignore the other cards that happen, the 4 cards need to be considered for the function call to have the expected result, so call the function for each card and check the output of the last one

1 Like

Ah, okay I see now. I wasn’t understanding that the “After the cards…” meant to make multiple logs. Thank you!

it is not necessary to do multiple logs, it is necessary to do multiple function callls to cc

1 Like

Got it, thanks for clarifying.