Hi fellow campers !
As exercises are getting more difficult, so do the texts, describing the tasks.
It’s a second time I have a problem understanding what exactly is wanted from me.
Please help me correctly interpret the following text in Italian style:
You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.
What is meant by “the function will then return a string with the current count” ?
Does it mean I have to use return statement ? if so, how can I return ‘Bet’ or ‘Hold’ afterwards, if executing RETURN statement is the last thing performed by JS. it stops after it.?
Do they really want me to return a string with the current count ?
Do I have to create an array with the all possible numbers as strings ?
Hope to learn understanding correctly the tasks like this.
Thanks in advance!
Happy Easter everyone !
Thanks for such a a quick reply. Maybe I haven’t explained my questions well enough. sorry.
count variable holds numbers, not strings, if I use RETURN (return count), I won’t be able to return anything else within this Switch Statement. Does it mean that it’s better to create another statement, lets say IF, which will return HOLD/BET ?
If I understand correctly, I have to create a statement, which will change the count and then check if the count variable is less or equal to zero.
One more thing: I think that before each entry of a new card value the count will be equal to zero, as there is no loop. That way we can’t count correctly multiple cards. Is it right ?
my code
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 += 1;
break;
case 7:
case 8:
case 9:
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
if(count <= 0){
console.log(count);
console.log('Hold');
}else{
console.log(count);
console.log('Bet');
}