Tell us what’s happening:
Why doesn’t my code pass the tests?
In the developer console, my code shows the results that should be in the tests.
Your code so far
var count = 0;
function cc(card) {
// Only change code below this line
if(card >= 2 && card <= 6) {
count++;
} else if (card == 10 || card == 'J' || card == 'Q' ||
card == 'K' || card == 'A') {
count--;
} else if (card >= 7 && card <= 9) {
count = count;
}
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');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
.
Challenge: Counting Cards
Link to the challenge:
ILM
2
there is a space missing in the output
1 Like
Marmiz
3
Hi @gregomur, welcome to the forum.
I suggest re thinking your return statements:
if (count <= 0) {
return count + ' Bet';
} else {
return count + ' Hold';
}
In the simple case of
2, 3, 4, 5, 6 should return 5 Bet
your function is returning:
5 Hold
Are you sure you should Bet
only if count is less or equal 0
?
Hope it helps 
1 Like
Thank you, I wasn’t attentive. I changed the return values:
if (count <= 0) {
return count + ' Bet';
} else {
return count + ' Hold';
}
but the code also fails the tests.
ILM
5
look at @Marmiz post, it points out the other issue
1 Like
Thank you very much, now I understand what was wrong