Tell us what’s happening:
I am completely stuck at this challenge and don’t know how the function sequences work.
Pleeeeeeese help.
Your code so far
js
var count = 0;
function cc(card) {
// Only change code below this line
if(card === 2&&card === 3&&card === 4&& card === 5 &&card === 6){
return "5 Bet";
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
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_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards
It seems you are approaching this from the wrong angle
You are trying to see if the card
variables is 5 different things at once, but that will never be possible
You need to check the value of card
and based on that you need to change (or not change) the global count
variable, and then based on the count
variable your function should return the current value of count
with “Hold” or “Bet”
You are just trying to pass the tests, which will not really work easily because of how they are set up, the easiest thing is to just follow challenge instructions
The function sequence will change the global variable count
based on each card passed in, and the last function will return the thing that matter for that case
I don’t completely understand what you are saying, I tried what I do, and I am still stuck. 
First thing first, try to change the value of variable count
based on the value of card
following the challenge instructions - as only one card is passed in you just need to do that. This will be your first step.
Once you have done that the other step is easier
You can do this in various ways, you just need a way to execute a piece of code if a condition is satisfied
it still didn’t work, but I got some code that I tried:
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 = card + 1;
break;
case 7:
case 8:
case 9:
count = card;
break;
case 10:
case 'J':
case 'Q':
case 'A':
case 'K':
count = card-1;
break;
}
if(count > 1){
return count + "Bet";
}
if(count < 1){
return count + "Hold";
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
It didn’t work but you are on the right way
First thing, if you change the value of count
you need to do it using the previous value of count
If count
is 0, and card
is 10, you need to lower count by one and make it -1
, your code instead do count = card - 1
so that would be 9
Fix that and you are a step closer
Second thing, you have condition for count > 1
and count < 1
but you are not doing anything for when count is 1
Third thing, you are returning strings like 0Hold
, 1Bet
- you are missing a space
Please read carefully the notice there’s only increments or decrements so you shouldn’t have something like count = card + 1; or count = card;
Also the the if test should with 0 (if positive)
and finally add space to the string in return statement