[SOLVED] Selecting from many options with Switch Statements - need understand what I do wrong

[SOLVED] Selecting from many options with Switch Statements - need understand what I do wrong
0.0 0


Hello everyone, I am doing “Selecting from many options with Switch Statements” Challenge and I just got stuck.
Please, what do I do wrong ? Thank you.

My code:

[spoiler]function caseInSwitch(val) {
var answer = “”;
// Only change code below this line

switch (answer) {
val = 1:
val = 2:
val = 3:
val = 4;

// Only change code above this line
return answer;

// Change this value to test


Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - “delta”



I don’t want to give you the answer, but it seems you are missing the “case” in the switch case:
https://www.w3schools.com/js/js_switch.asp this will help give you some insight.

If you are still stuck I’ll help push you further


After the word “switch” in parentheses you need “val” and not “answer”.
You have to use “case 1” instead of “val = 1”.
Also, you have to set the answer variable to the words like:
answer = “alpha”


That’s just not how switch statements are formatted in JavaScript.

It goes:

switch (variable you are testing here) {
case 1:
do something here;


I don’t know what freeCodeCamp teaches you these days, but you need to revisit basic Javascript.
There are many things that you are doing wrong, but I’m just going to give you some clues.

Do you understand the switch clause? If so, where are your cases for switch?
What does alpha, beta, gamma, and delta mean in your program? Are they variables? Do they hold any value? If they do, how are you using them?


Beta , gamma and delta are not vairables… They are just answers, console.logs that will show user something … For example, if VAR val = 1, so it will show user “alpha” It means that if number inside the caseInSwitch ( ) is for example 4, the answer is “delta”, because this code.
case 4:
answer = “delta”;

case 4 is case for my switch

Is it right ? (sorry for my bad english )


Well it seems like you’ve got a gist of it, but in your code, you’ve never declared them as a variable; so they are undefined.

You just wrote yourself these lines

case 4:
answer = "delta";

compare these lines to what you’ve wrote and fix your code.


Yes, now it’s ok… I think I understand it. Thank you gunhoo93, your answers was really helpful


Thank you for the help and clarification, it was really helpful in understanding the switch and case.