Counting cards(*sleeping*)

Tell us what’s happening:
Ok so back to this after other day site wouldnt let me fix mistakes. Anymew so here i am doing the code but it failed. Can anyone help fix this?? Its kinda confusing still.

Your code so far

...
var count = 0;

function cc(card) {
// Only change code below this line
 case 2:
 case 3:
 case 4:
 case 5:
 case 6:
    count++;
 break;
 case 7:
 case 8:
 case 9:
    count 0;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
    count--;
break;
default:
break;

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 5.1.1; KFDOWI) AppleWebKit/537.36 (KHTML, like Gecko) Silk/77.3.1 like Chrome/77.0.3865.116 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

Your switch statement is missing something right at the beginning.

Also,

 case 7:
 case 8:
 case 9:
    count 0;

count 0; is incorrect syntax.
Anyways, if card is 7, 8, or 9 you want count to stay the same. so you don’t have to do anything for those cases. Just leave them out.

Ty got the beginning part fixed and still missing something else apparently. Lol.

well thats hard to do on mobile. And if i make a mistake i have to reset code alot. I added this
after i added the switch(val) which i forgot to add earlier on. Maybe that’ll help yall understand what the prob is. Its saying now SyntaxError: unknown: Unexpected token (35:0) with the if statement added. I feel i about got it. But not clicking for me

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

StrayLove

2h

Fixed forgetting to add a switch(val) at beginning of code
Fixed to add if statement
Now reviewing

Your code so far

...
var count = 0;

function cc(card) {
// Only change code below this line
switch(val){
 case 2:
 case 3:
 case 4:
 case 5:
 case 6:
    count++;
 break;
 case 7:
 case 8:
 case 9:
    count 0;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
    count--;
break;
default:
break;
}
if (count > 0){
  count + " Hold";
}else{
   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(2); cc(3); cc(7); cc('K'); cc('A');

This took a bit to get copied and pasted and written. Like i said all i added was the if statement.

How to show current code with low effort:

  1. Press the ask for help
    button
  2. Copy the content of the post
  3. Cancel post (do not create new thread!)
  4. Come here, paste, and create a new post in this thread

this is wrong syntax

and even if you fix this, remember that code in a switch statement execute till it meets a break

this, being after a break in, supposedly, a switch statement, will never be executed.

this is the only return statement in the function, so once you fix the syntax errors, this is what’s going to be the output.

Ty but i just copied it from here once i remembered i could. Lol. Tyvm for that idea. Welp I’ll be sitting and reviewing what i done wrong.

you said you added the switch(val) { but it’s not there in the code you posted

there can’t be an accurate help without seeing your actual code

Re-edited to show it there. Annd the if statement

you can ignore then the comment to the first quote I did (I am going to edit that message too, so you can reference just what’s there.

I add this tho:

Your switch statement is not closed.

Next time you need other hints about what else to fix please use the process above to post your code so it will be exactly what’s in your editor. Sometimes it’s one character that makes all the difference and if you don’t copy and paste exactly it is not possible to know if that is the issue or not.


also you may find this interesting:

Tell us what’s happening:

This is still doing the exact same thing even after fixing it. Went thru the video for help as well and still this test wont go thru.

Your code so far


var count = 0;

function cc(card) {
 // Only change code below this line
switch(card) {
 case 2:
 case 3:
 case 4:
 case 5:
 case 6:
   count++;
   break;
 case 10:
 case "J":
 case "Q":
 case "K":
 case "A":
   count--;
   break;
}
var holdbet = 'hold'
if(count > 0) {
  holdbet = 'bet'
}
return count + " " + holdbet;
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 5.1.1; KFDOWI) AppleWebKit/537.36 (KHTML, like Gecko) Silk/77.3.1 like Chrome/77.0.3865.116 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

Your code logic is fine.

Just take a careful look at how the result should be capitalized.