Basic JavaScript - Counting Cards

Hi!
I am struggling with this portion of the course - I have done exactly what the video and solution 1 suggested but it still doesn’t accept it - is this something I am doing wrong is is it the questions? pls help

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;
}
if (count > 0) {
return count + “Bet”
} else {
return count + “Hold”
}

let count = 0;

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

  // 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Try console.loging one of the function calls. What does the output look like?

when I console.log console.log(cc(2,3,4,5,6)) I get 1Bet - I can’t figure out how to create the space - it won’t accept + “” + and I can’t get it to show 5 Bet like its saying it should. the only output that is close to being correct is console.log (cc(7,8,9) and comes out as 0Hold - no space :frowning:

This isn’t a correct function call

But you have the correct issue.

Where are you putting that?

This is what my code looks like :

 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; 
 }
if (count > 0) {
  return count + "" + "Bet";
} else {
  return count + "" + "Hold";
}

That string contains, literally, nothing. What do you want to put between the number and the “Hold”/“Bet”?

The output is supposed to have a space between the count and either of the strings “Hold” or “Bet” - i.e., instead of 0Bet it should say 0 Bet

Right. So should you put a string with literally nothing inside of it there or one with a space inside of it?

holy crap Jeremy you’re a genius! It works now - thank you so much!

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.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.