I’ve just finished the Switch Statements challenge and have a question about how they work.
In the following function (from the challenge), at what point is the returned string assigned to the answer
variable? In other words, How does returning answer
give the correct output?
function switchOfStuff(val) {
var answer = "";
switch (val) {
case "a":
return "apple";
break;
case "b":
return "bird";
break;
case "c":
return "cat";
break;
default:
return "stuff";
break;
}
return answer;
}