Hello! I was wondering how the instructor knew for the problem that count++ needed to be added? There was a previous module with Golf that did not use ++
Please provide a link to the challenge so we can see what you are referring to
My friend is full-stack developer at Amazon and even he said he had trouble with this one. When he watched the solution, he said there was no way you could’ve known how to do some of these steps with no experience lol
You seem to be talking about the Counting Cards challenge. I am not sure to which instructor you are referring or what specific code you are looking at that uses count++
, but I do see in the Hint section for the challenge, it is used in both solutions.
count++
is the same as writing count = count + 1
or count += 1
. It is more out of convenience and simplicity that count++
is used. The author understand this and that is probably why it was used.
Note that incrementing was covered previously in this lesson:
Also, how are we supposed to know to use
return count + " " + holdbet; ?
Where in the problem does it show that we should use empty string?
That is not an empty string. Look carefully, it is a string containing a single space character. Think about what the return value would look like without that extra space character.
The current count and the player’s decision (
Bet
orHold
) should be separated by a single space.
Example Outputs:
-3 Hold
or5 Bet
Got it…well, if I understood ALL of the previous lessons and know how to do switch, why wasn’t I able to solve the problem? ): If I can’t solve a problem in a beginner course, should I even continue? It will only just get harder from here and there is no “homework” for practice
This stuff is hard! It’s normal to struggle. What you should do when you get stuck is ask questions on the forum.
So right now I know how to make functions and switches, so it is normal to not know how to solve the problem? For example, how are we supposed to know that we are supposed to make a variable called holdbet? where does it say to do that?
Hello there! I am wondering why this is still showing incorrect? I am referring to Counting Cards module.
function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;
var holdbet = 'Hold'
if (count > 0) {
holdbet = 'Bet'
}
}
//return string with count and holdbet
return count + " " + holdbet //return string with count and bethold
// Only change code above this line
}
cc(2); cc(3); cc(7); cc('K'); cc('A');```
There are a bunch of ways to tackle ttis. You don’t need to have a variable called holdbet for instance.
I moved your post over here since it is part of the same conversation.
When I first pasted your code into the editor it gave me an error saying that count is not defined.
Make sure you didn’t delete this line of code at the top of the file
let count = 0;
A few things.
It looks like you are close to solving it, you just need to clean up this last part here.
First off, I would not have that if statement inside the switch.
Take it out of the switch statement.
Also, I personally don’t think you need this holdbet variable at.
I know some solutions include it but it is not really needed.
You want to refactor this portion here
The logic, if count is greater than 0 return the count and Bet else return count and Hold
I think simplifying will make your life a lot easier.
Hope that helps!