Question about console.log

Tell us what’s happening:

while trying the challenge on switch statements, and reading the extra info on mozillas page, I noticed they used console.log right before the statement, but I don’t understand why. I tried console.log in front of my statements and it didn’t work. What is the difference between the examples on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch and my answer below?

Your code so far

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
   switch (val) {
    case 1:
      answer = "alpha";
      break;
       case 2:
      answer = "beta";
      break;
       case 3:
      answer = "gamma";
      break;
       case 4:
      answer = "delta";
     break; 
   } 
  
  // Only change code above this line  
  return answer;  
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/selecting-from-many-options-with-switch-statements

Your code shows a function which changes the answer variable which is returned at the end based on what input value it is given. console.log on the other hand, is simply printing a value, and not returning a value from the function, so while they may look the same, you want to be returning the value after the switch statement and not console.logging based on the case. If you do not return a value from the function, it returns undefined.