Freecodecamp: Counting Cards(Not Working)

Created on 11 Mar 2016  路  7Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Counting Cards has an issue.
User Agent is: Mozilla/5.0 (Windows NT 5.1; rv:44.0) Gecko/20100101 Firefox/44.0.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

var count = 0;
function cc(card) {
// Only change code below this line
switch (card) {
case 'J':
case 'Q':
case 'K':
case 'A':
case 10:
count--;
}
if (count < 7) {
count++;
}
if (count <= 0) {
return count + " Hold";
}else if (count > 0) {
return count + " Bet";
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(3); cc(9); cc('Q'); cc(8); cc('A');

It looks to me like this code works. Several users in the chat said this should work. But, I keep on getting it wrong. I believe this is a bug,

Most helpful comment

_Content Hidden - by mod [raisedadead]_

All 7 comments

Nope, not a bug. Hint, here's your problem:

if (count < 7) {
count++;
}

Just one thing here needs to change and your code will pass. If you compare this if statement with your switch statement you'll see what's wrong.

Ah... Thank you @alistermada Didn't realize that I put in the wrong variable. Thank you!

Thanks @alistermada !

_Content Hidden - by mod [raisedadead]_

_Content Hidden - by mod [raisedadead]_

_Content Hidden - by mod [raisedadead]_

@ouzatl please do not post solutions or code on this thread, you can visit chat rooms and forum for assistance on code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raisedadead picture raisedadead  路  3Comments

MichaelLeeHobbs picture MichaelLeeHobbs  路  3Comments

Tzahile picture Tzahile  路  3Comments

ar5had picture ar5had  路  3Comments

QuincyLarson picture QuincyLarson  路  3Comments