could you plz tell me what is wrong with my code:
here is the question:
Write a switch statement which tests val and sets answer for the following conditions: 1 - alpha 2 - beta 3 - gamma 4 - delta
and this is my code:
function caseInSwitch(val) {
let answer = “”;
// Only change code below this line
switch(answer){
case 1:
console.log(“alpha”);
break;
case 2:
console.log(“beta”);
break;
case 3:
console.log(“gamma”);
break;
case 4:
console.log(“delta”);
break;
}
// Only change code above this line
return answer;
}
thank you so much.
Sara
**Your code so far**
function caseInSwitch(val) {
let answer = "";
// Only change code below this line
switch(answer){
case 1:
console.log("alpha");
break;
case 2:
console.log("beta");
break;
case 3:
console.log("gamma");
break;
case 4:
console.log("delta");
break;
}
// Only change code above this line
return answer;
}
caseInSwitch(1);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Selecting from Many Options with Switch Statements
The instructions say to “set answer”. No matter what the input is to your current function, it always returns an empty string, which is what answer is initialized to.
Thank you so much for your reply. But the let answer = “”; statement is typed by the site not me and it says only change the code below it.
How should I change it?
and pay closer attention to the switch syntax. Each case should be paired with an expected value to evaulate with. If i expect val to be equal 3, it would look like case 3: