Thank you for taking time to help me out. I really appreciate it.
Hello Syl @syllie
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.
Thanks a lot !! Very helpful!!
Carlos
from Spain
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
Do you mean like this?:
switch (val) {
case “1”:
console.log(“alpha”);
break;
case “2”:
console.log(“beta”);
break;
case “3”:
console.log(“gamma”);
break;
case “4”:
console.log(“delta”);
break;
}
Hi lexi,
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 setsanswer
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).
Very close! Keep going, you’re doing great.
Hi Syl,
‘Brandjesblussen’ it was hahaha. Thanks for the clear explanation…I’m not there yet
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
Hi Scott! It is a tough one isn’t it! If you look back in this thread you’ll see that a few others got tripped up by it too. I have written 2 posts with some additional hints and pointers for this exercise and they are linked here:
This one explains a bit more about how the ‘switch’ works:
And this one explains a strategy on how to tackle this particular problem
For the last one you may need to have a look at the screenshot by Lina too, but it is not too far above that.
With Carlos’ tips and these posts you may be able to tackle the problem. If you need more help - just shout out.
Hi Enzo,
Maybe also have a look at this link I just posted as I try to explain how it works:
If you need more help let us know.
Thank you Syl, I find the default statement a bit more comprehensible as well now (found it in the next exercise) and did too much code (apparently) to get to the same answer. Will try it out!
Hi there,
Don’t really understand why a property needs to be in single or double quotes when updating it with bracket notation, since we’ve learned that only properties with spaces in their name need quotes?
const myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog["bark"] = "woof" instead of myDog[bark] = "woof"
Pls i don’t know where to click to code,it seems the page is unresponsive. Can someone give me a guide?
Thanks
You don’t have a variable or function called bark in your code. The property name needs to be a string when dealing with quote marks.
However, dot notation is different. With dot notation, you must use a property name without quote marks. This is because handling a property with dot notation is not done so as a string.
In short myDog.bark
is equivalent to myDog["bark"}
.
I don’t think there’s a “why” so much as the syntax not allowing it.
Please go to freeCodeCamp.org to sign up and get an account and get started!
If you go back to the first lesson, you’ll find that info