Hello,
I understand the concept of switch statements, but this question still confuses me slightly. I read both solutions and the second makes sense to me (in that solution, we set
case 4:
answer = ‘delta’,
break;
for example, making a direct connection with the blank string variable defined in the function). However, this code below confuses me because I do not see how the returned string values for each case would “connect” to substitute for the “answer” variable. Basically, how do the cases with returned values serve/substitute as the blank-stringed “answer” variable? Thanks.
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch(val) {
case 1:
return 'alpha';
break;
case 2:
return 'beta';
break;
case 3:
return 'gamma';
break;
case 4:
return 'delta';
break;
}
// Only change code above this line
return answer;
}
caseInSwitch(1);
**Your browser information:**
Challenge: Selecting from Many Options with Switch Statements
Link to the challenge: