Hello fellow coders,
What a nice day to have a discussion isn’t it?
I just completed the Counting Cards Challenge but I feel like my code is really sloppy and it can be improved, that’s why I have several questions:
- I added too many lines of code?
- Is there something I could have done better?
- Is the switch statement better than the else if statement?
Also I’m curious to see how you approached this challenge. What was your code like?
Here is mine:
var count = 0;
function cc(card) {
// Only change code below this line
if (card >= 2 && card <= 6) {
count++;
} else if (card >= 7 && card <= 9) {
count+= 0;
}
else {
count--;
}
if (count <= 0) {
return count + " Hold";
} else {
return count + " Bet";
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc('J'); cc(9); cc(2); cc(7);
Cheers,
Alexandru.