Tell us what’s happening:
I have tried multiple versions of solutions, and while they haven’t worked, I am now wondering if I should somehow traverse an array or possibly linked list to get this done. I’ve tried various if/else if/else statements. I’ve tried switch statements. I’ve also tried the solution, but I haven’t figured out what to change to make it work. Nothing works.
Your code so far
var count = 0;
function cc(card) {
// Only change code below this line
switch(card){
case 2:
count+1;
break;
case 3:
count+1;
break;
case 4:
count+1;
break;
case 5:
count+1;
break;
case 6:
count+1;
break;
case '10':
count-1;
break;
case 'J':
count-1;
break;
case 'Q':
count-1;
break;
case 'K':
count-1;
break;
case 'A':
count-1;
break;
}
if (count > 0){
return count + "Bet";
} else {
return count + "Hold";
}
//___________other versions
if (count >0 &&<7){
card = card+1;
return card + "Bet"; //needs count positive sign checker
} else if (count ==0) {
return card; //may need other condition
} else (count <0){
card = card-1;
return card + "Hold";
}
//-------
if (count > 0) {
if (card >0 &&<7){
count = card+1;
count++
return count + "Bet"; //needs count positive sign checker
} else if (card >= 7 && <=9) {
return count; //may need other condition
} else (card > 9){
count = card-1;
count--;
return card + "Hold";
}
return count + "Bet";
} else {
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');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards/