Tell us what’s happening:
Sorry, I’m confused. Again. Help!
**Your code so far**
function caseInSwitch(val) {
function caseInSwitch(val) {
let answer = "";break;
// Only change code below this line
caseInSwitch(1):
let answer="alpha";
break;
caseInSwitch(2):
let answer="beta";
break;
caseInSwitch(3):
let answer="gamma";
break;
caseInSwitch(4):
let answer="delta";
break;
// Only change code above this line
return answer;
}
caseInSwitch(1);
caseInSwitch(2);
caseInSwitch(3);
caseInSwitch(4);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
Challenge: Selecting from Many Options with Switch Statements
You can’t re-declare variables like this and get the outcome you are expecting.
Using let again, this line says, ‘create a new variable called answer, set it to “alpha”’. But you already have a variable named answer inside of the function, so you should get an error.
Make sure and only change the code between the green lines that say so. It will help a lot!
function caseInSwitch(val) {
let answer = "";
// Only change code below this line
switch(val) {
case "1":
answer = "alpha";
break;
... and continue with this pattern....
}
// Only change code above this line
return answer;
}
caseInSwitch(1);
function caseInSwitch(val) {
let answer = "";
// Only change code below this line
switch(val){
case "1":
answer="alpha";
break;
case "2":
answer="beta";
break;
case "3":
answer="gamma";
break;
case "4":
answer="delta";
break;
}
// Only change code above this line
return answer;
}
caseInSwitch(1);
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.