Even though i did solve the problem, i m still confused in visualizing how. I don
t fully understand why count is returned with the string instead of the card. My attempts with switch statements failed primarily because i was stuck on how to end with the default, i checked the hints and hint 3 was very confusing on how switch and if statements are combined. My solution is guess work. :pensive
Your code so far
let count = 0;
function cc(card) {
// Only change code below this line
if (card == 2 || card == 3 || card == 4 || card == 5 || card == 6) {
count++;
} else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A') {
count--;
}
if (count > 0) {
return count + " Bet";
} else { return count + " Hold"}
// 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/113.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Counting Cards
Link to the challenge: