Hi,
Thanks in advance for your help.
I am working on the “Selecting Many Options With Switch Case” problem. I am having a lot of trouble getting my code to pass the tests.
I am certain that I understand the logic. I believe that the problem is syntax. I have searched the forums and the web for examples of correct syntax. I am trying to use the correct syntax, but the console won’t accept it. I can modify the case syntax to something that the console will accept, but then it refuses to accept a “break ;” statement.
First, the logic. In a switch function a value is passed to the function with a variable. The value is compared in sequence top to bottom by strict equivalence. When a match is found, the code for that specific instance is executed then, a break statement should be executed. I know that every case does not have to include a break statement, and I know that not including a break statement can be used to group cases.
Second, the code:
switch(val){
var answer = " ";
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
answer = "delta";
return answer;
}
Assuming I sent a numeric value to switch(val), a value of 1,2 or 3 should return “alpha”, "beta "or “gamma” respectively. Anything else should return “delta”.