Multiple Identical Options in Switch Statements var

Hello. I am trying to understand why the switch() function requires a variable. How is var answer linked to switch(val). Thank you


function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {
    case 1:
    case 2:
    case 3:
      return 'Low';
      break;
    case 4:
    case 5:
    case 6:
      return 'Mid'
      break;
    case 7:
    case 8:
    case 9:
      return 'High'
      break;
  }
  
  
  // Only change code above this line  
  return answer;  
}

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




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements/

Well, it needs to know what to compare to 1, 2, 3, etc.

It doesn’t need a variable. You are correct that you could simply return based on the case and whatever is passed in through the val argument. Just different solutions but one will follow more closely with what FCC is asking for. You are essentially shortcutting by creating your own return instead of using the return provided.