You got stuck there. I had same problem.
remember cc is the name of the function and we will get only two output. Bet or hold
if count is greater than zero , result is bet
if it is a negative value or 0(-1,-2,-3,-4 ,or 0) result is hold;
I think you feel difficulty to understand this is because you did not understand switch statement
I am not an expert. but i will try to implement this with if statement, then i will try to explain switch
var count=0;
function cc(card){
if(card===2||card===3||card===4||card===5||card===6){
/the count value is zero. when you pass value 2 or 3 4 or 5 or 6 count will be added by one
example
cc is the name of the function
what is the value of count now?
value of count is zero
now i invoke function
cc(2)
what is the value of count now?
one
because this condition is true
/
cc(3)
i invoke the function again
what is the value of count three
how many time this function satisfy this block of code condition as true , it add one by one
count++
}
else{ if(card===10||card===‘J’||card===‘Q’||card===‘K’||card===‘A’){
//same thing here instead of adding it will be subtract
count–
}
else{
//if cc(0) don’t add or subtract, keep the value same
//example
// cc(2) it satisfy the first condition so it added the count"s value by one
now value of count is 1
after that I invoke cc(0)
what is the value of count now:
one
then
if i invoke cc(‘A’)
value of count will be zer
count
}
}
var answer;
if(count;<=0){
//if count lessthan or equal to zero Hold
answer= ‘Hold’
}
else {
if count greater than zero Bet
answer=‘Bet’
}
console.log(count)
return answer;
}
//going to invoke function count (initial value of count is 0) answer
cc(2); count=count+1 =0+1=1 Bet
now value of count =1
cc(2); count=count+1 =1+1=2 Bet
now value of count =2
cc(3) count=count+1 =2+1=3 Bet
now value of count =3
cc(0) count=count+1 =2+1=3 Bet
now value of count same (3) we have not set any arithmetic operation when we invoke function with argument zero
value of count =3
cc(‘A’) count=count-1 =3-1=2 Bet
cc(‘A’) count=count-1 =2-1=1 Bet
cc(‘A’) count=count-1 =1-1=0 Hold
cc(‘A’) count=count-0 =0-1=-1 Hold
in switch statement ‘case’ we use instead of || in if statemen
for example
var value=1
function m(a,b){
if(a<value||b<value){
return value
}
}
in switch statement
var value=1
function m(a,b)
switch(value)
case a<value:
case b<value
return ’ did you understand ’
default :
return slight_smile: