Question on "Basic JavaScript: Adding a Default Option in Switch Statements"

Question on "Basic JavaScript: Adding a Default Option in Switch Statements"
0

#1

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?


#2
function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line
  
  
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
switchOfStuff(1);

This is actually the initial template given to us. You can click on reset button to see this. So it is actually returning answer variable.


#3

@shimphillip lol I guess when I was playing around with things, I forgot I was the one to put it in there! Derp! :roll_eyes: Thanks for letting me know where I went wrong!