using switch with multiple identical cases

this can be used if you have several outcomes where the return value will be the same by omitting the break from the cases before the final

Javascript

function lmh(val) {
  var out = "";
  switch(val) {
    case 1:
    case 2:
    case 3:
      out = "Low";
      break;
    case 4:
    case 5:
    case 6:
      out = "Mid";
      break;
    case 7:
    case 8:
    case 9:
      out = "High";
      break;
  }
  return out;  
}

console.log(lmh(1));
console.log(lmh(9));

Demo

Other Items in javascript
Page Views

This page has been viewed 98 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹