// Only change code below this line
if (card >= 2 && card <= 6){
return count++;
}else if (card==10 || typeof card===“string”){
return count–;
}if (count<=0){
return (count+" Hold");
} else {
return (count+" Bet");
}
return “Change Me”;
// Only change code above this line
}
Can anyone tell me why the result is always 1 less than it should be?
For example, when I tested CC(2)~CC(6), the output only displayed 4 instead of (5, Bet).
Can anyone tell me where did I get wrong?
A walkthrough helps when code produces unexpected results - a good walkthrough is when you pretend to be the computer and simply execute the code line by line variable by variable without explanation or thinking - in fact trying to think or understand during a walkthrough is counterproductive
That’s just my walkthrough notes for line 2 of your code - think of it as a comment representing the state of the program when line 2 is executed for CC(2)
When line 2 runs the program uses the value of count which is 0 for the return value of the function - then count is incremented and becomes 1 - since count is global its value remains 1 for the next call of CC(3)
The bad styling was causing the code to be unable to do it’s job properly, this might of been due to it’s use in the switch, I’m not sure, if I have time I’ll go back and investigate further but for now ++ and – incrementation will always save the day. And I can just write a for loop if I need to increment by 100 and what-not. This javascript stuff is getting fun - at first I felt a bit intimidated but now I’m enjoying it