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:
alpha;
break;
val = 2:
beta;
break;
val = 3:
gamma;
break;
val = 4;
delta;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);[/spoiler]
Instructions:
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.
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”
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”;