Basic JavaScript - Counting Card

Its not even accepting my codes to test. Ive tried 3 different ways.

Your code so far

let count = 0;

function cc(card) {
  // Only change code below this line
if (card <= 6) {
  count += 1;
}else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A") {
  count -= 1;
}
 if(count <= "Hold";
 return count + "Hold";
}else {
return count + "Bet";
}
  // Only change code above this line



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Counting Cards

if(count <=0){

return count + “Hold”;

}else {

return count + “Bet”;
I seen that mistake after I made the post. But it still will not accept that.

You may be missing a curly bracket at the end of your function.
If so, you should see a syntax error in the console.
If not, then the only remaining issue with your code should be the value which you are returning.
You need to include a space, otherwise your output will be along the lines of ‘-1Hold’ (instead of ‘-1 Hold’).

function cc(card) {

// Only change code below this line

if (card <= 6) {

return count = 1;

}else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A") {

return count = -1;

}

if(count <=0){

return count + "Hold";

}else {

return count + "Bet";

}

}

I fixed what you said but its still is not checking off that anything is correct.

Using conventional styling helps

function cc(card) {

  // Only change code below this line
  if (card <= 6) {
    return count = 1;
   } else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
    return count = -1;
  }

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

Two big issues here.

  1. return immediately stops the function

  2. why are you setting count to -1 or 1?

Bc the directions say to return 1 or -1.

I didnt have “return” in there until I seen an example that had it so I added it. Before it only said “count”.

Nope. Go copy paste the part of the instructions. The instructions don’t say ‘return 1 or -1’.

You are copying somebody else’s bug. Part of the danger in copying answers

Count Change Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, ‘J’, ‘Q’, ‘K’, ‘A’

Where does that text say ‘return’? Looks like it says ‘count change’!

I didnt have "return in there at 1st but it did not accept it then either.

You changed code which was previously correct. If you revert to the code which you originally posted and then make the spacing modification which I suggested, your code should pass.

Essentially, your first conditional statement, which checks the value of each card, should NOT return a value, only increment or decrement the count variable (as it did in your original code).

Your final conditional statement should return the value of count and the corresponding string, with correct spacing.

So don’t copy stuff that you find.

If the instructions don’t say ‘return 1’, then you probably shouldn’t.

What does ‘count change’ mean? It doesn’t mean to set count to 1 or -1!

I took out the returns at the top and took out any extra spacing…still nothing.

Did you fix this problem?

Its hard to guess what’s wrong if you don’t post your updated code!

if(card < 6) {

count <= 1;

}else if(card == 10||card == "J"||card == "Q"||card == "K"||card == "A") {

count >= -1;

}

if(count <=0){

count + "Hold";

}else{

count + "Bet";

}

}

You are such a great help. Thank you.

I would first not delete all those other lines.

I would also fix your formatting, like I said above.

What does this do? It doesn’t change count

It adds the count if the card is less than or equal to. Right??

‘add’ should involve a + though