Basic JavaScript - Counting Cards

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

this evening the compiler started saying that the my first return statement was outside the function… before that it said that I was getting the first three test correct…also does my last return statement need a closing bracket.

let count = 0;

function cc(card) {
  // Only change code below this line

if (card <= 6 ) {
++ count ;

}else if (card == 7 || 8 || 9 ) {
count += 0 ;

}
-- count ;

}


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

return count + " Hold" ; 


  return "Change Me";
  // 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

your code syntax was wrong.
let count = 0;

Mod Edit: SOLUTION REMOVED

hello, thts really nice of you to help but its recommended that we dont give full answer, rather help them to find it our for themselves, its better that way, happy helping :slight_smile:

1 Like

hello and welcome back to fcc forum :slight_smile:

  • wrong syntax

you might want to separate those (i.e. conditions in correct syntax, for example a === b || b === c || ....) individually and try again, happy learning :slight_smile:

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Was it bad to use if else and or?..can i even do that…
what about this
switch (card) {

case 2 || 3 || 4 || 5 || 6 :
++ count ;
break ;
case 7 || 8 || 9 :
count += 0 ;
break ;
default:
– count ;
break ;

}

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

}
return count + " Hold" ;

i see what about this

if (card <= 6) {

++ count ;

}else if (card === 7 || card === 8 || card === 9 ) {

count += 0 ;

}

– count ;

if (count > 0){

return count + " Bet" ;

}

return count + " Hold" ;

This is what i got to initially

Also it still didnt wrk

This isn’t how a switch works

i tried this but it doesn’t work either

switch (card) {

case 2 :
++ count ;
break ;
case 3 :
++ count ;
break ;
case 4 :
++ count ;
break ;
case 5 :
++ count ;
break ;
case 6 :
++ count ;
break ;
case 7 :
count += 0 ;
break ;
case 8 :
count += 0 ;
break ;
case 9 :
count += 0 ;
break ;
default :
– count ;
break;

}

if (count > 0) {

return count + " Bet";
}
return count + " Hold";
}

actully typo but i put the break after 9