Ale1
April 16, 2021, 2:06pm
1
Tell us what’s happening:
**Your code so far**
var count = 0;
function cc(card) {
if (card = 2 || 3 || 4 || 5 || 6) {
return count++;
}
else if (card = 7 || 8 || 9) {
return count = 0;
}
else if(card = 10 || 'J' || 'Q' || 'K' || 'A') {
return count--;
}
var holdbet = "Hold";
if (count > 0) {
return count + "" + holdbet;
}
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
what should I change in order to let this program works?
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
.
Challenge: Counting Cards
Link to the challenge:
Ale1:
return count = 0
You shouldn’t set count
to 0 here. You should add 0 to the count
.
Do NOT reset count
to 0 when value is 7, 8, or 9.
1 Like
Ale1
April 16, 2021, 2:13pm
3
can you show me the correct code ?
Nope. We don’t give out solutions.
But, you are pretty close. You need to not set count to 0.
Once you have fixed that, you have a few more bugs.
Ale1:
return count++;
Ale1:
return count--;
Returning from a function stops the execution. If you return the count, then the rest of the function never executes.
I don’t see "Bet"
here anywhere. In which case should you return a string with "Bet"
?
Ale1:
""
This is an empty string. Why are you putting an empty string in between your count and your holdbet
string?
Ale1
April 16, 2021, 2:46pm
5
var count = 0;
function cc(card) {
if (card = 2 || 3 || 4 || 5 || 6) {
count++;
}
else if (card = 7 || 8 || 9) {
count;
}
else if(card = 10 || 'J' || 'Q' || 'K' || 'A') {
count--;
}
var holdbet = 'Hold';
if (count > 0) {
holdbet = 'Bet';
}
return count + " " + holdbet;
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
This still doesn’t work
Ale1
April 16, 2021, 2:47pm
6
the empty string is for the space
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
1 Like
An empty string ""
is different than a space " "
. It looks like you fixed that though.
Real close. Question: how do you check multiple conditions? (Hint: this isn’t it )
Ale1
April 16, 2021, 3:00pm
10
with the || (OR) operator…I’ve also tried with the && operator but it returns me the same inefficiency…
The || operator checks
(full logical conditional) || (other full logical conditional)
Are you comparing full conditions?
ILM
April 16, 2021, 3:02pm
12
well, first you need to remember that =
is the assignment operator, you are assigning a value to the variable, not comparing it
also ||
works as condition1 || condition2
, your condition2
is 3
which is not complete as a condition
1 Like
Ale1
April 16, 2021, 3:09pm
13
var count = 0;
function cc(card) {
if ((card = 2) || (card = 3) || (card = 4) || (card = 5) || (card = 6)) {
count++;
}
else if ((card = 7) || (card = 8) || (card = 9)) {
count;
}
else if ((card = 10) || (card = 'J') || (card = 'Q') || (card = 'K') || (card = 'A')) {
count--;
}
var holdbet = 'Hold';
if (count > 0) {
holdbet = 'Bet';
}
return count + " " + holdbet;
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
This still doesn’t work…
ILM
April 16, 2021, 3:10pm
14
the first issue I pointed out still stands
Ale1:
=
There is a big difference between =
, ==
and ===
.
Ale1
April 16, 2021, 3:29pm
16
var count = 0;
function cc(card) {
if ((card = 2) || (card = 3) || (card = 4) || (card = 5) || (card = 6)) {
count = count + 1;
}
else if ((card = 7) || (card = 8) || (card = 9)) {
count = count + 0;
}
else if ((card = 10) || (card = 'J') || (card = 'Q') || (card = 'K') || (card = 'A')) {
count = count - 1;
}
var holdbet = 'Hold';
if (count > 0) {
holdbet = 'Bet';
}
return count + " " + holdbet;
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
where i am wrong ?
ILM
April 16, 2021, 3:31pm
17
you are still not checking the value of card
but assigning a new value to it
Did you look up the difference between =
, ==
and ===
? You seem to not be listening to @ILM .
1 Like
Ale1
April 16, 2021, 3:34pm
19
Thank you guys…sorry for being a little stupid
system
Closed
October 16, 2021, 3:34am
20
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.