Counting Cards is driving me crazy!

Tell us what’s happening:
Hi people! I’m coming back to programming after so many years. I’m kinda frustrated with this because I saw the solution but still I’m not finding the error in my code. Would you please help me figure it out? How can I run the code so I know what is failing? Thanks a lot!!

Your code so far


var count = 0;

function cc(card) {
// Only change code below this line
if (card > 1 && card < 7) {
count++;
}
else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "a") {
count--;
}
// Only change code above this line



if (count > 0) { 
return count + "Bet";
} else {
return count + "Hold";
}
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0.

Challenge: Counting Cards

Link to the challenge:

Capitalization is important.

Also, I think you are missing a space in your output.

1 Like

Hello and welcome to the freeCodeCamp community~!

In addition to @JeremyL’s comment, spacing is equally important. You are very close.

1 Like

Omg it was the space. Thanks a lot nhcarrigan and JeremyLT, love you both!

1 Like

Jorge,
The best question you asked was about how can you check this. There are a lot of things
that can help. Notice how the code editor in the lessons has some things Baked-in behind the scenes? Like the place holder text “test output goes here” . What makes it go away? I’ve noticed it picks up when you complete a function. Sometimes experimenting with other code editors can show you things the test suite doesn’t. try “codepen.io”.
I used to over-declare variables because it gave me more ability to log the outputs. Between which set of brackets, above or below a specific code will log different values for the same var. The more byzantine the wording of your console.log(parameter); the less likely I find it will understand. Just play around with it and keep asking the questions. Lastly, I have heard people say FCC JS cert is super hard. I wouldn’t know because this is my first time coding, but knowing that helped me emotionally. Just look at it like you are learning piano as an adult. Be curious, not too shy to ask, and look at the time you spend scripting as practice time. Personally, I spent 4 hours last night working on a program to save me 5 minutes. it FAILED but I saved my work for later. Its play time. Have fun.

var count = 0;
function cc(card) {
// Only change code below this line
if (card > 1 && card < 7) {
count++;
}
else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "a") {
count--;
}
// Only change code above this line
console.log(count);
if (count > 0) { 
return count + "Bet";
} else {
return count + "Hold";
}
}
console.log(count);
console.log(cc(2));
console.log(cc(2, 3, 4, 5, 6));
cc(2); cc(3); cc(7); cc('K'); cc('A');

returns

0
1
1Bet
2
2Bet
3
4
4
3
3

I just saw this answer, sorry. This is so incredible helpful as well, like for coding in general. Thanks a lot for this input man, really! Hope you enjoy this journey as well!