Okay, so I’m revisiting previous JS challenges since I was stumbling so much the first time through it. I was going through “Basic JavaScript: Adding a Default Option in Switch Statements” and was having difficulty passing it even though it basically looked right to me (especially when compared to other forum posts on the same challenge).
My original code:
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch(val) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default:
answer = "stuff";
break;
}
// Only change code above this line
return switchOfStuff;
}
// Change this value to test
switchOfStuff(1);
However, it wouldn’t pass. Then, after looking at someone else’s code, I didn’t return the var
answer. At first, I overlooked the // Only change code above this line
comment and replaced return switchOfStuff;
with return answer;
and it passed. BUT, I wasn’t supposed to replace return switchOfStuff;
so put it back and went back above the comment code and now have this:
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch(val) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default:
answer = "stuff";
break;
} return answer;
// Only change code above this line
return switchOfStuff;
}
// Change this value to test
switchOfStuff(1);
QUESTION: If I had completely removed and replaced return switchOfStuff;
with return answer;
would that have hurt me somehow if “real world” coding? Please explain.
SIDE NOTE: It passed the challenge even without bringing back return switchOfStuff;
so is that line even relevant?