Not sure what to do with these since i’m already using some of these values? Like, maybe switch statement wasn’t the best choice here because i can’t use || like inside a if statements parentheses?
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++;
return count + " Bet";
break;
case 7:
case 8:
case 9:
return count + " Hold"
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
return count + " Hold";
break;
}
// 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 6.2; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0.
I don’t understand how the below would fix the 2 remaining sequence? because 0 is an int right and j is a string? which in the image below J isn’t an int so not sure how count > 0 knows j is a string?
You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table).
And then return a value based on count
The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.
If you have made changes and still need help please post your new code
I just looked at the solution because would have never thought of the code below without looking at the solution. I also still don’t understand how count can know about J …anyways thanks all
The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it’s not exactly the same.
For instance, case matters. A capital letter "A" is not equal to the lowercase "a" . Which one is greater? The lowercase "a" . Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode). We’ll get back to specific details and consequences of this in the chapter Strings.
you change count based on the value of card:
if the card is 2,3,4,5,6 count is increased by one
if the card is 7,8,9 count is not changed
if the card is 10,J,Q,K,A count is decreased by one
then the valye of count is checked, and based on that the output is determined
I don’t understand how the below would fix the 2 remaining sequence? because 0 is an int right and j is a string? which in the image below J isn’t an int so not sure how count > 0 knows j is a string?
cc(2) : 2 is in the first group of cards, so count is increased by one (count is 1)
cc(J) : J is in the third group of cards, so count is decreased by 1 (count is 0)
cc(9) : 9 is in the second group of cards, so count is not changed (count is 0)
cc(2) : 2 is in the first group of cards, so count is increased by 1 (count is 1)
cc(7) : 7 is in the second group of cards, so count is not changed (count is 1)
now, the Bet/Hold part is decided by the value of count
The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.
more specifically:
a string with the current count and the string Bet if the count is positive
so you need to return “1 Bet” in this case, because count is positive
instead you are returning “1 Hold” beacuase of this return statement:
I already looked at the solution and copied it i don’t need help solving this i need you to explain to me how count 0 knows of “j” which is a string not an int.
You stated earlier;
and i replied to the above with a yes or no answer?
becase your issue is that you are returning values from inside the switch
that means that you are not checking what’s the value of count before returning a value
you are returning Hold just because the card is a 7, not because you are checking what’s the value of count
instead you need to have two separate parts of the function, one changing count, and one determining the output of the function based on the value of count
I’m done here we are not getting anywhere…you said " "J" is not associated with an int, "J" is a string" but then you said " if count is 10 , then the next card is `“Q”.
So if count is -1 that equals all the Hold Cases that are negative and “J” is a case which is a string !!! so the count int is grabbing the string J and its associated which = Yes to the question i asked 3 times…
Update - I can’t reply anymore so read here for now on ( hit reply limit )
but i’m saying any negative number aka if count is -1 it knows of the strings that make count–;
Milku86 - I get that but count knows of each card based on its value 1 or 0 or -1 each card is connected to 0 or 1 or -1 right? so what i’m trying to say is -1 = all the cases that make count decrement? right?
ieahleen - so yes i was right case “j”: is -1 so then count > 0 makes sense then to me. 10, “A”, “J”, “K”, or “Q” equals the count value of -1 so this is how that if statement knows of the strings…