You are attempting to use the increment/decrement operator, but you wrote it with a space between the name and operator. Try it again using these operators correctly, like so: count++ and count--. I did not review your full code so there may be other things you need to change, but this is definitely not working as intended.
I now looked closer at your code, and sorry for not pointing this out earlier, but your case returns a string regardless of the actual value of count. As the count variable lives in the global space, it will keep its value on each call to the function. So to solve this challenge successfully, you need to do this in 2 steps:
Evaluate the card and add either +1, 0, -1 to the count variable
Evaluate the count variable, and if it is positive, return the current count and Bet, otherwise return the current count and Hold
Some other tips:
note that you do not need to ‘add’ anything when the card is 7, 8 or 8 - so you could consider leaving these out of the ‘case’ evaluation, if:
you evaluate and return the solution outside of the switch (aka: use the switch to change count, return your function after the switch)
you can stop evaluating the card after you found its value as case - so it would be better to break; (but the last case evaluation does not need it as you are done anyways).
I hope this helps Lina. If you are still stuck - let me know and I will post a code sample.
pfew Remco, you got me good there! I looked at your code and thought omygosh did I miss anything here as I cannot remember us doing so many (and such specific) condition checks!
I see what you have done, and yes you got the code to pass - but not in the right way yet. From the code I can see you had difficulties passing the test cases, and to deal with that you wrote a complex piece of code that dealt with each condition separately ( I use an analogy like: think of frying a piece of bacon, you press down where it bubbles up, only to see another bubble appear in a different spot - or in dutch: ‘brandjesblussen’). This way we coders would need to write hundreds of lines to make a function work and it still would not do. You did too much work!
Now to your problem. What we had to solve was:
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined
It asks you to do 2 checks, and you get the value of a and b in the header. This is really as easy as
if ( (a < 0) || (b < 0) ) {
return; // as returning from a function without a value automatically is 'undefined' .
}
You could do this as a one liner too, but again I usually use bracket notation all the time, just so I can slip in extra code with ease and never get confused what is part of a block and what not.
I am on discord too if you want a bit of a broader discussion around this.
the === operator checks for both value and type and is the strictest way to evaluate if the things that are compared are exact matches. The exercise works with == too, but an exact matching is better.
I don’t mean to bother you… but I just wanted say:
Thank you for all your post, they are impresive: informatives, well explained,… Apart of intelligent, you are very kind and empathetic in your messages! I better stop, lol.
I dont know if I got better after reading you, but I got some positive energy and strength to keep going for sure, and I needed it that is why I got the courage to write this.
Hello! For switch “Selecting from Many Options with Switch Statements”, I am wondering what do we need to put after “switch”? val? or caseInSwitch
I wrote like this, but it is not right:
switch (caseInSwitch) {
case “1”:
console.log(“alpha”);
break;
also what does this mean? :“RangeError: Maximum call stack size exceeded”
You need to use val as the expression to decide.
What you have done is called the function caseInSwitch where the switch statement is in and created an infinite Loop. That the reason for the Range Error
You are nearly there! Andre sent you on the right track and you now test ‘val’. If you re-read the instruction, then that should have followed from there:
Write a switch statement which tests val and sets answer for the following conditions:
So it expects your switch to take the variable val and test that, like so:
switch(val){
...
}
Then from the table we see the outcome of the test and what answer it should yield:
1 - alpha
2 - beta
3 - gamma
4 - delta
If no type is given, this means ‘the number 4’ and ‘the string delta’. So your case tests should read like
switch(val){
case 1 : // no quotes as we test a number
answer = "alpha"; // the assignment tells us to 'set answer'
break;
...
}
The switch will take the value passed into the function caseInSwitch(val){..} and test it in the switch switch(val){...} against the known outcomes 1,2,3,4 for case and when found, it sets the value for answer to the correct string, and then steps out of the switch with break.
You can leave the last break out as the switch is finished but leaving it there is absolutely fine (and consistent).
So, I’m really struggling with the Counting Cards exercise. I don’t even know where to begin, would you suggest me going back over the previous few lessons and Youtube tutorial to see if I can wrap my head around it, or is it better to watch the solution video and move on? Bit stuck on how I should handle this. Thanks in advance.
Hi @scott2920053
I would suggest you to read the problem carefully try to understand all they want, even take your notes and then move on to next challenge, you can do that.
Next day back to the problem and try to break it down in small chunks, and solve it. If after 5 min you still dont know what to do, click on Get Help / Get a Hint. There you will see some Hints and even solutions. Try to solve it again with those Hints. If you still cannot do it, just back and check some solutions and try to understand them.
Mark that challenge and back to it when you feel more comfortable with JavaScript.
Dont worry much about it, dont waste too much time in one challenge, think about it a few minutes and take breaks, it helps. But always try to understand the hints and even the solutions, and check the suggested links in MDN.
I hope my wookie english make sense.
Hey @carlost2672543 thanks for replying I appreciate that! I’ll take what you said on board. I’ll try and give it another go over the weekend with a fresh mind and see what happens and take it from there. As you say I can come back to it so I’ll mark the lessons I find tricky and see if they improve as I progress
Not completely understanding the relationship between the SWITCH and CASE functions. I grasp the basic concept, but not the implementation of its mechanics in practice. Hope to get some more exercises to practice it