Basic JavaScript - Counting Cards

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

This code should work. The debugger is not very helpful

Your code so far

let count = 0;

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

 if (card > 1 || < 7) {
  count++;
}
else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
  count--;
}
if (count > 0) { return count + "Bet";
}
if (count <0) { 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/106.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

This is not how you write an if statement with multiple conditions

if (card >= 2 || card <= 6) {
count++;

Did you fix the other conditional?

let count = 0;

function cc(card) {

// Only change code below this line

if (card >= 2 || card <= 6) {

count++;

}

else if (card == 10 || ‘J’ || ‘Q’ || ‘K’ || ‘A’) {

count–;

}

if (count > 0) { return count + ‘Bet’;

}

else if (count < 0) { return count + ‘Hold’;

}

// Only change code above this line

}

cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);

Still error

Your function should return a value for count and the text (

Bet

or

Hold

) with one space character between them. Cards Sequence 2, 3, 4, 5, 6 should return the string

5 Bet

Cards Sequence 7, 8, 9 should return the string

0 Hold

Cards Sequence 10, J, Q, K, A should return the string

-5 Hold

Cards Sequence 3, 7, Q, 8, A should return the string

-1 Hold

Cards Sequence 2, J, 9, 2, 7 should return the string

1 Bet

Cards Sequence 2, 2, 10 should return the string

1 Bet

Cards Sequence 3, 2, A, 10, K should return the string

-1 Hold

Yup. You have more bugs. Did you try console logging the output.

That is the output i posted. Weird problem. It should be right. Im gonna skip

You posted the test output.

You have no debugging statements.

You should manually run a test case and look at the output with a console.log statement

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

Your code so far

This code should work. Bizarre.

let count = 0;

function cc(card) {
  // Only change code below this line
  
  if (card > 1 && card < 7) {
    count++;
  } else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
    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/106.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

You should fix this, like i saif above.

this if statement will return true if card is 10
but will also return true if card is not 10
that’s because you said || ‘J’ etc.
and ‘J’ is always true (J is J and it is not false, therefore it is true)

let count = 0;

function cc(card) {
// Only change code below this line
var regex = /[JQKA]/;
if (card > 1 && card < 7) {
count++;
}
else if (card === 10 || regex.test(card)) {
count–;
}
if (count > 0) { return count + " Bet"; }
if (count < 0) { return count + " Hold";}

// Only change code above this line
}

cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);

This is as close as im going to get without copying the solution.

MY only error is

Cards Sequence 7, 8, 9 should return the string

0 Hold

if (card >= 7 || card <= 9 ) { return count; }

I added in that syntax to make the count neither count up or count down but i am not sure if this is correct

What happens when count is 0?

Return stops the function

Well i assumed that much. I have no other way to continue the count without adding or subtracting. Do you?

In C++ i could just say

if (count = 0) { continue ; }

Why do you need a continue? Why not just not omit that if case?

The system needs to know what to do if i 7 , 8 or 9 is pulled

So if anyone knows how to fix

Cards Sequence 7, 8, 9 should return the string 0 Hold

I’ll be excited to hear !