Counting cards: If statements or Switch?

I just want to clarify that I understand the assignment. Is this correct?

The count variable means that for each card that falls between 2 and 6, you add one point. So if you have a hand with a 2, 3, and 4, you have 3 points.

7-9 would be no points, and 10 and up would be -1 points.

I started working on this, and began using if statements, but it looks like you have to use switch statements? Is it possible to solve this challenge with something like this? Or am I barking up the wrong tree and I should change all this to switch statements?

function cc(card) {
  // Only change code below this line
if (card >= 2 && card <=6) {
  count = card++ // I realize this is wrong.
  return count + " Bet";
} else if (card >=7 && card <=9) {
  return count + " Hold";
} else if (card > 9 || "J" || "Q" || "K" || "A") {
  count = card-- //This is not how to do it.
  return count + " Hold";

  return "Change Me";
  // Only change code above this line
type or paste code here

You can solve this challenge with a pair of if-[else if]-else statements, but the challenge expects you to use a switch, I believe. (Not sure if the tests check for the use of a switch or not)

1 Like

Hope I can help:

var count = 0;
var verb = 0
function cc(card) {
  // Only change code below this line
  if(card>1 && card <7){(count++)}
  else if(card>6 && card<10){}
  else if(card == 10, 'J','Q','K','A'){count--}

  if(count >0){verb = "Bet"}
  else if (count == 0){verb = "Hold"}
  else ("hold")

  return count +" "+verb;
  // Only change code above this line

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


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.

Thank you for understanding.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thanks, got it to pass, finally.

this is not a valid comparison, when you use the OR operator each condition must be complete on it’s own: condition1 || condition2 || condition3, but instead "J" is not a complete condition

Thank you, yes, I figured that out eventually. I finally came up with a solution that passed.